/**
 * 框架js,tool为系统变量,请勿在其他页面重新初始化
 * Created by tengchong on 15/7/21.
 */
/**
 * page 二级页面对象,切换菜单将重新初始化
 * subPage 三级页面对象,切换菜单将重新初始化
 * @type {{}}
 */
var page = {},
    subPage = {};
var subview_id = [];
/**
 * tool 工具对象
 * @type {{choseLeftStageMenu: string, choseTopStageMenu: string, leftStageMenuList: Array, menuList: Array, res_form: null, configDebug: boolean, userloginid: null, usertype: null, group: null, waitForResponseStatusBtn: null, fileUpload: null, procee: string, submitForm: tool.submitForm, loadFormByTr: tool.loadFormByTr, showAllQueryTeam: tool.showAllQueryTeam, youdaoLanguage: tool.youdaoLanguage, resetForm: tool.resetForm, importData: tool.importData, exportData: tool.exportData, exportDataForDbf: tool.exportDataForDbf, exportDataByForm: tool.exportDataByForm, exportDataByFormForDbf: tool.exportDataByFormForDbf, getChoseData: tool.getChoseData, CropCheckBoxValueAsString: tool.CropCheckBoxValueAsString, editData: tool.editData, editDataById: tool.editDataById, addData: tool.addData, addDataByLcbm: tool.addDataByLcbm, addDataBackByLcbm: tool.addDataBackByLcbm, saveData: tool.saveData, openloading: tool.openloading, closeloading: tool.closeloading, getTop: tool.getTop, openSubviewByForm: tool.openSubviewByForm, getTabName: tool.getTabName, delHtmlTag: tool.delHtmlTag, openSubview: tool.openSubview, ajaxError: tool.ajaxError, alertLogin: tool.alertLogin, alert: tool.alert, alertInfo: tool.alertInfo, alertSuccess: tool.alertSuccess, alertSuccess_lc: tool.alertSuccess_lc, alertError: tool.alertError, alertWarning: tool.alertWarning, alertConfirm: tool.alertConfirm, doRemoveAll: tool.doRemoveAll, deleteAllData: tool.deleteAllData, doRemove: tool.doRemove, deleteDataById: tool.deleteDataById, deleteData: tool.deleteData, doSearch: tool.doSearch, doSaveSearch: tool.doSaveSearch, initOrderTables: tool.initOrderTables, initOrderTable: tool.initOrderTable, initSubViewBox: tool.initSubViewBox, addRow: tool.addRow, initEditRow: tool.initEditRow, initSaveRow: tool.initSaveRow, initDelRow: tool.initDelRow, save_row: tool.save_row, del_row: tool.del_row, edit_row: tool.edit_row, initFileUpload: tool.initFileUpload, has_flash: tool.has_flash, initFileUploadByConfig: tool.initFileUploadByConfig, initPageHeight: tool.initPageHeight, openModal: tool.openModal, openModalStatic: tool.openModalStatic, openModalStaticFor: tool.openModalStaticFor, modal: tool.modal, removeDateForEditTable: tool.removeDateForEditTable, removeDateForEditTable: tool.removeDateForEditTable, upDateForEditTable: tool.upDateForEditTable, downDateForEditTable: tool.downDateForEditTable, randomString: tool.randomString, getString: tool.getString, submit_save: tool.submit_save, super_doSearch: tool.super_doSearch, doModify: tool.doModify, openview: tool.openview, openReport: tool.openReport, openEntity: tool.openEntity, super_reset: tool.super_reset, downloadfile: tool.downloadfile, initParams: tool.initParams, setWaitForResponseStatus: tool.setWaitForResponseStatus, removeWaitForResponseStatus: tool.removeWaitForResponseStatus, showWaitTip: tool.showWaitTip, setWaitTip: tool.setWaitTip, hideWaitTip: tool.hideWaitTip, isNotEmpty: tool.isNotEmpty, isEmpty: tool.isEmpty, isDebug: tool.isDebug, emptyHtml: tool.emptyHtml, emptyValue: tool.emptyValue, emptyTextarea: tool.emptyTextarea, report: tool.report, report_s: tool.report_s, report_all: tool.report_all, report_open: tool.report_open, report_open_input: tool.report_open_input, iserror: tool.iserror, getlog: tool.getlog, getlog_htm: tool.getlog_htm, showlog_all: tool.showlog_all, openimport: tool.openimport, closeimport: tool.closeimport, initbtnQx: tool.initbtnQx, initbtnQxBack: tool.initbtnQxBack, closeCurrentTab: tool.closeCurrentTab, reloadTab: tool.reloadTab, reload: tool.reload, disableEditTable: tool.disableEditTable, enableEditTable: tool.enableEditTable, deleteFileRow: tool.deleteFileRow, addUploadAttachmentRow: tool.addUploadAttachmentRow, addUploadImageRow: tool.addUploadImageRow, addUploadVideoRow: tool.addUploadVideoRow, previewImage: tool.previewImage, previewImageByPath: tool.previewImageByPath, previewImageByUrl: tool.previewImageByUrl, previewVideo: tool.previewVideo, initFileIcon: tool.initFileIcon, getFileIcon: tool.getFileIcon, validationElement: tool.validationElement, initchart: tool.initchart, choseParam: tool.choseParam, choseParamBack: tool.choseParamBack, authenticationAuthority: tool.authenticationAuthority, initAutosize: tool.initAutosize, initSummerNoteBySelector: tool.initSummerNoteBySelector, initSummerNote: tool.initSummerNote, initDatetimepickerBySelector: tool.initDatetimepickerBySelector, initDatetimepicker: tool.initDatetimepicker, initSelectBySelector: tool.initSelectBySelector, initSelect: tool.initSelect, initSearchSelectBySelector: tool.initSearchSelectBySelector, initSearchSelect: tool.initSearchSelect, initBootstrapSelectBySelector: tool.initBootstrapSelectBySelector, initBootstrapSelect: tool.initBootstrapSelect, initiCheckBySelector: tool.initiCheckBySelector, initiCheck: tool.initiCheck, initvalidationEngine: tool.initvalidationEngine, initAlertHis: tool.initAlertHis, initBtnShow: tool.initBtnShow, supportHtml5: tool.supportHtml5}}
 */
var tool = {
    choseLeftStageMenu: '1',
    choseTopStageMenu: '1',
    leftStageMenuList: [],
    menuList: [],
    res_form: null,
    configDebug: true,
    userloginid: null,//用户账户
    usertype: null,//用户操作权限
    group: null,//用户组
    waitForResponseStatusBtn: null,
    fileUpload: null,
    procee: '/pros/',
    /**
     * 提交表单 for search
     * @param form_element 要提交表单的对象 | 不可为空
     * @param callback 回调函数
     */
    submitForm: function (form_element, parm, callback) {
        if (parm == null) {
            parm = true;
        }
        var el = form_element.parents(".panel");
        if (el.length == 0) {
            el = form_element;
        }
        if(el.length != 0){
            el.block({
                overlayCSS: {
                    backgroundColor: '#fff'
                },
                message: '<i class="fa fa-spinner fa-spin"></i>',
                css: {
                    border: 'none',
                    color: '#333',
                    background: 'none'
                }
            });
        }
        var url = form_element.attr("data-action");
        if (!parm && url.indexOf('?') > -1) {
            url = url.substring(0, url.indexOf('?'));
        }
        $.ajax({
            url: tool.initParams(url),
            cache: false,
            type: "post",
            data: form_element.serialize(),
            dataType: "html",
            timeout: 1000 * 60,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                tool.ajaxError(XMLHttpRequest, textStatus, errorThrown);
            },
            success: function (data) {
                if (tool.iserror(data)) {
                    return false;
                }
                el.unblock();
                var $data = $(data);
                form_element.find('select').attr('data-val', '').attr('data-value', '');
                form_element.find("input[type='text'],input[type='hidden'],select").each(function (e) {
                    $(this).attr("exportData-val", $(this).val());
                });
                if (form_element.attr("data-action").indexOf("errorList") > -1) {
                    form_element.find(".dataTables_wrapper").html(data);
                } else {
                    //更新表格内容
                    form_element.find(".dataTables_wrapper").eq(0).html($data.find(".form-horizontal .dataTables_wrapper").eq(0).html());//刷新table > list
                    //更新分页信息
                    form_element.find(".page-info:eq(0)").html($data.find(".form-horizontal .page-info:eq(0)").html());
                    form_element.find(".page-info:eq(1)").html($data.find(".form-horizontal .page-info:eq(1)").html());
                    //更新汇总信息
                    var i = 0;
                    el.find('div.alert').each(function () {
                        var $el = $(this);
                        $el.html($data.find('div.alert:eq(' + i + ')').html());
                        i++;
                    })
                    $("td[hide]").each(function () {
                        var trindex = '';
                        var str = $(this).attr("hide");
                        var strs = str.split("=");
                        if (strs[0] == strs[1]) {
                            trindex = $(this).parents("tr").find("td").index($(this));
                            $(this).hide();
                            if (trindex != null && trindex != '') {
                                $("table th:eq(" + trindex + ")").hide();
                            }
                        }
                    });

                }
                Main.initList(form_element.find("table"));
                initselectcode();
                init_lanagure();
                try {
                    page.submitFormCallBack(data);
                } catch (e) {

                }
                if (isFunction(callback)) {
                    callback();
                }
                if (isFunction(page.pageCallBack)) {
                    page.pageCallBack();
                }
            }
        });

    },
    /**
     * 通过点击tr在form下面加载新list
     */
    loadFormByTr: function (el, url, type) {
        var form_element = $(el).parents('.form-horizontal');
        if (type == '1') form_element = $(el).parents('.form-horizontal-tr');
        var el = form_element.parents(".panel");
        if (el.length != 0) {
            el.block({
                overlayCSS: {
                    backgroundColor: '#fff'
                },
                message: '<i class="fa fa-spinner fa-spin"></i>',
                css: {
                    border: 'none',
                    color: '#333',
                    background: 'none'
                }
            });
        }
        var data = '';
        if (form_element.attr('data-action') == url) {
            data = form_element.serialize()
        }
        $.ajax({
            url: tool.initParams(url),
            cache: false,
            type: "post",
            data: data,
            dataType: "html",
            timeout: 1000 * 15,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                tool.ajaxError(XMLHttpRequest, textStatus, errorThrown);
            },
            success: function (data) {
                el.unblock();
                var htm = '<form method="post" class="form-horizontal-tr">' +
                    '<input type="hidden" id="orderType" name="orderType" value="${orderType}">' +
                    '<input type="hidden" id="orderField" name="orderField" value="${orderField}">' + data + '</form>';
                var this_element = null;
                if (form_element.attr('data-action') == url) {
                    form_element.html(htm);
                    this_element = form_element;
                } else {
                    if (form_element.next('.form-horizontal-tr').html() != undefined) {
                        form_element.next('.form-horizontal-tr').html(htm);
                    } else {
                        form_element.after(htm);
                    }

                    this_element = form_element.next('.form-horizontal-tr');
                }
                Main.initList(this_element.find("table tbody"));
                this_element.attr("data-action", url);
                initselectcode();
                if (url.indexOf("action") < 0) {//spring mvc
                    this_element.find("#yspager_currentPageno").attr("name", "currentPageno");
                    this_element.find("#eachPageRows").attr("name", "eachPageRows");
                }
                this_element.find("ul[class*='pagination']").find('a').each(function () {
                    $(this).attr("data-current-page-no-tr", $(this).attr("data-current-page-no"));
                    $(this).removeAttr("data-current-page-no");
                    $(this).unbind('click');
                });
                this_element.find("ul[class*='pagination']").find('a[data-current-page-no-tr]').click(function () {
                    var form_element = $(this).parents(".form-horizontal-tr");
                    form_element.find("#yspager_currentPageno").val($(this).attr("data-current-page-no-tr"));
                    tool.loadFormByTr(this, url, '1');
                });
            }
        });
    },
    /**
     * 用于查询条件超过2行时,显示隐藏多余的查询条件
     * 注:需要在需要隐藏/显示的元素上添加class 'more-query'
     * @param el 显示更多查询条件按钮 | 不可为空
     */
    showAllQueryTeam: function (el) {
        if ($(el).attr("data-state") == "open") {
            $(el).parents('.form-horizontal').find(".more-query").addClass("dn");
            $(el).removeAttr("data-state");
            $(el).html("更多 <i class=\"fa fa-angle-down\"></i>");
        } else {
            $(el).parents('.form-horizontal').find(".more-query").removeClass("dn");
            $(el).attr("data-state", "open");
            $(el).html("收起 <i class=\"fa fa-angle-up\"></i>");
            $('.form-horizontal .control-label').each(function () {
                var $el = $(this);
                if ($el.height() > 25) {
                    $el.addClass('wrap').removeClass('ell');
                }
            });
        }
    },

    youdaoLanguage: function (txt) {
        try {
            if (cookielang == "en") {
                $.ajax(
                    {
                        type: 'post',
                        url: '/pros/s/ajax/getyoudaovalue?txt=' + encodeURI(encodeURI(txt)),
                        dataType: 'text',
                        async: false,
                        success: function (data) {
                            txt = data;
                        },
                        error: function () {
                            console.log('fail');
                        }
                    }
                );
            }
        } catch (e) {
            // TODO: handle exception
        }

        return txt;
    },
    /**
     * 获取多图片上传列表信息
     * @param selector
     * @returns {Array}
     */
    getImageListSee: function (selector) {
        var list = [];
        var i = 0;
        var _temp = {};
        $('table[data-list="' + selector + '"]').find('tbody > tr').each(function () {
            _temp = {};
            var $el = $(this).find('td:eq(0)');
            console.log($el);
            _temp.name = $el.find('input:eq(0)').val();
            _temp.path = $el.find('input:eq(1)').val();
            ;
            if ($el.attr('is-see') == 'true') {
                _temp.isSee = true;
            } else {
                _temp.isSee = false;
            }
            list[i] = _temp;
            i++;
        });
        // console.log(list);
        return list;
    },
    /**
     * 重置查询条件
     * @param el 重置按钮 | 不可为空
     */
    resetForm: function (el) {
        $(el).parents('.form-horizontal').find("input:visible,select:visible").not(':disabled').not('[type="checkbox"]').not('[readonly]').not("table input").val("");
        $(el).parents('.form-horizontal').find("select:visible").not(':disabled').not('[readonly]').not('[type="checkbox"]').trigger("change");
    },
    /**
     * 打开导入页面
     * @param el 导入按钮 | 不可为空
     * @param par 参数 | 一般传入导入模板id
     * @param tab页标题
     */
    importData: function (el, par, name) {
        var form_element = $(el).parents('.form-horizontal');
        tool.res_form = form_element;
        var url = basePath + "/s/system/excelUserImport/openCreate?" + par;
        tool.openSubview(url, null, tool.getTabName(el, name), false);
    },
    /**
     * 在iframe中打开导出页面
     * @param par 地址+参数 | 不可为空
     */
    exportData: function (par, path) {
        if ((path == null || path == '') && nodePath != null && nodePath != '') path = nodePath;
        window.parent.tool.exportData(par, path, 'export2excel');
    },
    exportDataForDbf: function (par, path) {
        if ((path == null || path == '') && nodePath != null && nodePath != '') path = nodePath;
        window.parent.tool.exportData(par, path, 'export2dbf');
    },
    /**
     * 导出数据 (将导出按钮所在form表单数据作为参数通过url传入)
     * @param el this
     * @param par 参数
     * @param path url
     */
    exportDataByForm: function (el, par, path, is_dbf) {
        if ((path == null || path == '') && nodePath != null && nodePath != '') path = nodePath;
        var form_element = $(el).parents('.form-horizontal');
        var temp = '';
        var elList = form_element.find('input[type="text"],input[type="hidden"],select');
        elList.each(function () {
            var $el = $(this);
            temp += $el.attr('name') + '=' + $el.val() + '&';
        });
        if (elList.length > 0) {
            temp = temp.substr(0, temp.length - 1);
        }
        if (par.indexOf('?') > -1) {
            par = par + '&' + temp
        } else {
            par = par + '?' + temp
        }
        if (is_dbf) {
            tool.exportDataForDbf(par, path);
        } else {
            tool.exportData(par, path);
        }
    },
    /**
     * 导出数据 (将导出按钮所在form表单数据作为参数通过url传入)
     * @param el this
     * @param par 参数
     * @param path url
     */
    exportDataByFormForDbf: function (el, par, path) {
        tool.exportDataByForm(el, par, path, true);
    },
    /**
     * 获取所选数据
     * @param form_element 表单(jquery对象) | 不可为空
     * @returns {string} 选中数据的id | 示例 1,2,3,4
     */
    getChoseData: function (form_element) {
        var selectNode = form_element.find('input[name="selectNode"]:checked');
        var ids = '';
        if (!isBlank(selectNode)) {
            for (var i = 0; i < selectNode.length; i++) {
                ids += $(selectNode[i]).val() + ',';
            }
            ids = ids.substr(0, ids.length - 1);
        }
        return ids;
    },
    /**
     * 获取当前form中指定名称的checkbox选中列表
     * @param name checkbox名称 | 不可为空
     * @param el 按钮 | 不可为空
     * @returns {string} 选中数据的id | 示例 1,2,3,4
     */
    CropCheckBoxValueAsString: function (name, el) {
        var form_element = $(el).parents('.form-horizontal');
        var selectNode = form_element.find("input[name='" + name + "']:checked");
        var ids = "";
        if (!isBlank(selectNode)) {
            for (var i = 0; i < selectNode.length; i++) {
                ids += $(selectNode[i]).val() + ",";
            }
            ids = ids.substr(0, ids.length - 1);
        }
        return ids;
    },

    /**
     * 修改数据
     * @param el 修改按钮 | 不可为空 | 示例 this
     * @param subview_box 子窗口容器 | 可为空
     * @param manyChooseTip  多选时提示标题 | 可为空
     * @param manyChooseTip2 多选时提示子标题 | 可为空
     * @param noChooseTip   未选时提示标题 | 可为空
     * @param noChooseTip2 未选时提示子标题 | 可为空
     */
    editData: function (el, subview_box, manyChooseTip, manyChooseTip2, noChooseTip, noChooseTip2, params) {
        var form_element = $(el).parents('.form-horizontal');
        tool.res_form = form_element;
        var ids = tool.getChoseData(form_element);
        if (!isBlank(ids)) {
            if (ids.split(",").length == 1) {
                tool.editDataById(el, ids, subview_box, null, params);
            } else {
                if (manyChooseTip == "" || manyChooseTip == null || manyChooseTip2 == "" || manyChooseTip2 == null) {
                    tool.alertWarning('不支持批量修改,请勾选1条数据!', '请在下方列表中勾选一条要修改的数据');
                } else {
                    tool.alertWarning(manyChooseTip, manyChooseTip2);
                }

            }
        } else {
            if (noChooseTip == "" || noChooseTip == null || noChooseTip2 == "" || noChooseTip2 == null) {
                tool.alertWarning('请选择要修改的数据!', '请在下方列表中勾选一条要修改的数据');
            } else {
                tool.alertWarning(noChooseTip, noChooseTip2);
            }
        }
    },
    /**
     * 根据id修改信息
     * @param el 链接 | 不可为空 | 示例 this
     * @param id 数据id | 不可为空
     * @param subview_box 子页面容器 | 可为空
     */
    editDataById: function (el, id, subview_box, name, params) {
        tool.editDataByIdConfig({
            el: el,
            id: id,
            name: name,
            params: params
        });
    },
    /**
     * 根据id修改信息
     * @param el 链接 | 不可为空 | 示例 this
     * @param id 数据id | 不可为空
     * @param name 标签页名称
     */
    editDataByIdConfig: function (obj) {
        var form_element = $(obj.el).parents('.form-horizontal');
        tool.res_form = form_element;
        var url = form_element.attr("data-action");
        if (url.indexOf("action") < 0) {
            if (url.indexOf("/s/system") > 0) {
                url = url.substring(0, url.indexOf('/s/') + 10) + url.substring(url.indexOf('/s/') + 10).substring(0, url.substring(url.indexOf('/s/') + 10).indexOf("/"));
            } else if (url.indexOf("/s/id") > 0) {
                url = url.substring(0, url.indexOf('/s/') + 6) + url.substring(url.indexOf('/s/') + 6).substring(0, url.substring(url.indexOf('/s/') + 6).indexOf("/"));
            } else {
                url = url.substring(0, url.indexOf('/s/') + 7) + url.substring(url.indexOf('/s/') + 7).substring(0, url.substring(url.indexOf('/s/') + 7).indexOf("/"));
            }
            url = url + "/input/" + obj.id;
        } else {
            url = url.substr(0, url.indexOf("-")) + "-input.action?wid=" + obj.id;
        }
        if (url.indexOf('?') > -1) {
            url += '&' + obj.params;
        } else {
            url += '?' + obj.params;
        }
        tool.openSubview(url, null, tool.getTabName(obj.el, obj.name), true);
    },
    /**
     * 新增数据 注:form中class中包含parameter的将会自动作为参数传到后台
     * @param el 必填 | 当前form中的一个元素
     * @param parameter 参数 | 可选
     * @param subview_box 页面容器 | 可选
     */
    addData: function (el, parameter, subview_box, name, lcsearch) {
        var form_element = $(el).parents('.form-horizontal');
        tool.res_form = form_element;
        var data = form_element.find('input[class*="parameter"],select[class*="parameter"]').serialize();
        var url = form_element.attr('data-action');
        if (url.indexOf('action') < 0) {
            if (url.indexOf("/s/system") > 0) {
                url = url.substring(0, url.indexOf('/s/') + 10) + url.substring(url.indexOf('/s/') + 10).substring(0, url.substring(url.indexOf('/s/') + 10).indexOf("/"));
            } else if (url.indexOf("/s/id") > 0) {
                url = url.substring(0, url.indexOf('/s/') + 6) + url.substring(url.indexOf('/s/') + 6).substring(0, url.substring(url.indexOf('/s/') + 6).indexOf("/"));
            } else {
                url = url.substring(0, url.indexOf('/s/') + 7) + url.substring(url.indexOf('/s/') + 7).substring(0, url.substring(url.indexOf('/s/') + 7).indexOf("/"));
            }
            url = url + '/openCreate?time=' + new Date().getTime();

            if (parameter != null && parameter != '') {
                url += '&' + parameter;
            }
            if (lcsearch != null && lcsearch != '') {
                url += '&' + lcsearch;
            } else if (data != null && data != '') {
                url += '&' + data;
            }
        } else {
            url = url.substr(0, url.indexOf('-')) + '-openCreate.action?time=' + new Date().getTime();

            if (parameter != null && parameter != '') {
                url += '&' + parameter;
            }
            if (lcsearch != null && lcsearch != '') {
                url += '&' + lcsearch;
            } else if (data != null && data != '') {
                url += '&' + data;
            }
        }
        tool.openSubview(url, null, tool.getTabName(el, name), true);
    },
    /**
     * 新增数据，查看工作流有没有配置年度，配置了则打开数据
     */
    addDataByLcbm: function (el, lcbm, parameter, subview_box, name) {
        window.parent.tool.addDataByLcbm(el, lcbm, parameter, subview_box, name, tool);
    },
    /**
     * 新增数据，查看工作流有没有配置年度，配置了则打开数据,返回调用子项目方法
     */
    addDataBackByLcbm: function (el, lcbm, parameter, subview_box, name, p) {
        $.post(tool.initParams(tool.procee + 's/biz/ajaxProcess/opennd'), {'lcbm': lcbm}, function (data) {
            if (tool.iserror(data)) {
                return false;
            }
            var a = 0;
            var htm = '';
            var old = false;
            $(data).each(function (i) {
                if (data[i].wid == 'old') {
                    old = true;
                }
                if (!old) {
                    a++;
                    htm += '<a name="addDataBackByLcbm" class="btn btn-sm btn-green" onclick="" con="' + data[i].con + '">' + data[i].conMs + '</a>&nbsp;';
                }
            });
            if (old) {
                tool.alertWarning('不可以操作', '当前时间不在管理员开启的时间范围内，请联系管理员！');
            } else {
                if (a == 0) {
                    p.addDataBack(el, null);
                } else if (a == 1) {
                    p.addDataBack(el, data[0].con.replaceAll('and', '&').replaceAll('\'', '').replaceAll(' ', ''));
                } else {
                    swal({
                        title: "请选择条件",
                        text: htm,
                        html: true,
                        showCancelButton: true,
                        showConfirmButton: false
                    });
                    $('a[name*="addDataBackByLcbm"]').click(function () {
                        p.addDataBack(el, $(this).attr('con').replaceAll('and', '&').replaceAll('\'', '').replaceAll(' ', ''));
                        if (!isIE8) {
                            swal.close();
                        }
                    });
                }
            }
        });

    },
    /**
     * 保存数据
     * @param el 保存按钮 | 不可为空 | 示例 this
     * @param url 保存url | 可不指定
     * @param isAlert 是否弹出操作结果 默认弹出
     * @param isvalidate 是否验证 | 如不需要验证,传入true
     * @param callback 回调函数
     */
    saveData: function (el, url, isAlert, isvalidate, callback) {
        //暂时禁止按钮点击事件
        tool.setWaitForResponseStatus($(el));
        if (isAlert == null) {
            isAlert = true;
        }
        if (isvalidate == null) {
            isvalidate = false;
        }
        var form_element = $(el).parents('.form-horizontal');
        if (isvalidate || form_element.validationEngine('validate')) {
            //如果form中没有action
            if (isBlank(url)) {
                if (isBlank(form_element.attr("action"))) {
                    url = form_element.attr("data-action");
                    //spring mvc
                    if (url.indexOf("action") < 0) {
                        if (url.indexOf("/s/system") > 0) {
                            url = url.substring(0, url.indexOf('/s/') + 10) + url.substring(url.indexOf('/s/') + 10).substring(0, url.substring(url.indexOf('/s/') + 10).indexOf("/"));
                        } else if (url.indexOf("/s/id") > 0) {
                            url = url.substring(0, url.indexOf('/s/') + 6) + url.substring(url.indexOf('/s/') + 6).substring(0, url.substring(url.indexOf('/s/') + 6).indexOf("/"));
                        } else {
                            url = url.substring(0, url.indexOf('/s/') + 7) + url.substring(url.indexOf('/s/') + 7).substring(0, url.substring(url.indexOf('/s/') + 7).indexOf("/"));
                        }
                        url = url + "/save";
                    } else {
                        url = url.substr(0, url.indexOf("-")) + "-saveData.action";
                    }
                    //form_element.attr("action", url);
                } else {
                    url = form_element.attr("action");
                }
            }
            var backdrop = $('.ajax-white-backdrop');
            $(".main-container").append('<div class="ajax-white-backdrop"></div>');
            backdrop.show();

            $.ajax({
                url: tool.initParams(url),
                type: "POST",
                data: form_element.serialize(),
                dataType: "json",
                timeout: 1000 * 60 * 2,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    tool.ajaxError(XMLHttpRequest, textStatus, errorThrown, backdrop);
                },
                success: function (data) {
                    tool.removeWaitForResponseStatus();
                    backdrop.remove();
                    form_element.find("#is_change").val("0");
                    //noinspection JSUnresolvedVariable
                    if (data.oper_res) {
                        if (isAlert) {
                            setTimeout('tool.alertSuccess("' + data.oper_msg + '")', 100);
                        }
                        //如果表单中有 wid 元素 并且 data 对象中有wid属性
                        if (!isBlank(data.data)) {
                            if ("wid" in data.data && form_element.find("#wid").length != 0) {
                                form_element.find("#wid").val(data.data.wid);
                            }
                            if ("id" in data.data && form_element.find("#id").length != 0) {
                                form_element.find("#id").val(data.data.id);
                            }
                        }
                        try {
                            subPage.save_callback(data, form_element, el);
                        } catch (ex) {
                        }
                        if (isFunction(callback)) {
                            callback(data);
                        }
                    } else {
                        setTimeout('tool.alertError("操作失败!","' + data.oper_msg + '")', 100);
                    }
                }
            });
        } else {
            tool.removeWaitForResponseStatus();
            return false;
        }
    },
    openloading: function ($el, tit) {
        if (window.parent.tool != null) {
            window.parent.tool.openloading($el, tit);
        }
    },
    closeloading: function ($el) {
        if (window.top != window.self && window.parent.tool != null) {
            window.parent.tool.closeloading($el);
        }
    },
    getTop: function (e) {
        var offset = e.offsetTop;
        if (e.offsetParent != null) offset += tool.getTop(e.offsetParent);
        return offset;
    },
    /**
     * 根据当前form生成子窗口容器ID,并打开窗口
     * @param el form 表单内对象 | 不可为空
     * @param url url | 不可为空
     * @param check_issave 关闭页面时是否检测已经保存 | 可为空 | 默认不检测
     * @param need_res 关闭打开页面后是否刷新本页面 | 可为空 默认不刷新
     */
    openSubviewByForm: function (el, url, check_issave, need_res, id, name) {
        if (id == null || id == '') {
            id = new Date().getTime();
        }
        tool.openSubview(url, id, tool.getTabName(el, name), check_issave);
    },
    /**
     * 获取标签页名称
     * @param el
     * @param name
     */
    getTabName: function (el, name) {
        if (name == null || name == '') {
            if (!isBlank($(el).attr('data-tab-name'))) {
                name = $(el).attr('data-tab-name');
            } else {
                name = tool.delHtmlTag($(el).html());
                if (isBlank(name)) {
                    name = '新建标签页';
                }
            }
        }
        name = trim(name);
        // if (name.length > 9) {
        //     name = name.substr(0, 8) + '...';
        // }
        return name;
    },
    delHtmlTag: function (str) {
        return str.replace(/<[^>]+>/g, "");//去掉所有的html标记
    },
    /**
     * 打开子窗口
     * @param url url | 不可为空
     * @param id tab页id
     * @param name 页面标题
     * @param showLoading 是否显示loading
     */
    openSubview: function (url, id, name, showLoading) {
        if (name == null || name == '') {
            name = '新建标签页';
        }
        if (id == null || id == '') {
            id = new Date().getTime();
        }
        //检查当前页面是否为父页面
        window.parent.addTab(url, id, name, true, showLoading);
    },
    ajaxError: function (XMLHttpRequest, textStatus, errorThrown, backdrop) {
        tool.removeWaitForResponseStatus();
        if (backdrop != null) backdrop.remove();
        if (textStatus == "timeout") {
            setTimeout("tool.alertError('请求超时!', '请稍后重试!')", 100);
        } else {
            if ($(XMLHttpRequest.responseText).find('#error-message').length > 0) {
                setTimeout("tool.alertError('错误!', '" + $(XMLHttpRequest.responseText).find('#error-message').html() + "');", 100);
            } else if ($(XMLHttpRequest.responseText).find('#logout-error').length > 0) {
                setTimeout("tool.alertLogin();", 100);
            } else if ($(XMLHttpRequest.responseText).find('#logout-error-other-login').length > 0) {
                setTimeout("tool.alertLogin('您的账号正在其他设备登录！当前自动退出。');", 100);
            } else if ($(XMLHttpRequest.responseText).find('#error-info-404').length > 0) {
                setTimeout("tool.alertWarning('操作失败', '" + $(XMLHttpRequest.responseText).find('#error-info-404').html() + "');", 100);
            } else {
                setTimeout("tool.alertError('" + XMLHttpRequest.responseText + "');", 100);
            }
        }
    },
    alertLogin: function (info) {
        if (window.top != window.self) {
            window.parent.tool.alertLogin(info);
        }else{
            if (info == null) {
                info = '由于您长时间未进行操作,您的登录信息已过期';
            }
            swal({
                title: '重新登录',
                text: info,
                type: "error"
            }, function () {
                $.get("../identity/ajaxlogin.action?act=logout", {q: (new Date()).getTime(),userloginid:'<%=tsysUser.getUserloginid()%>'}, function (data) {
                    data = eval("(" + data + ")");
                    if (data.msg == 'success') {
                        if(iscas && window.location.href.indexOf('index.action')!=-1){
                            window.location = '<%=CasLoginUtil.getCasServerLogoutUrl()%>';
                        }else{
                            window.location = window.location.href;
                        }
                    } else {
                        tool.alert(data.msg);
                    }
                });
            });
        }

    },
    alert: function (obj) {
        if (window.top != window.self) {
            window.parent.tool.alert(obj);
        } else {
            swal(obj);
        }
    },
    alertInfo: function (txt, sub_txt) {
        if (window.top != window.self) {
            window.parent.tool.alertInfo(youdao(txt), youdao(sub_txt));
        } else {
            swal(youdao(txt), youdao(sub_txt), "info");
        }
    },
    alertSuccess: function (txt, sub_txt) {
        if (window.top != window.self) {
            window.parent.tool.alertSuccess(youdao(txt), youdao(sub_txt));
        } else {
            swal(youdao(txt), youdao(sub_txt), "success");
        }
    },
    alertSuccess_lc: function (txt, sub_txt) {
        if (window.top != window.self) {
            window.parent.tool.alertSuccess_lc(youdao(txt), youdao(sub_txt), subPage);
        } else {
            swal({
                    title: txt, text: sub_txt, type: "success",
                    closeOnConfirm: true,
                    closeOnCancel: false
                }, function () {
                    subPage.lc_callback();
                }
            );
        }
    },
    alertError: function (txt, sub_txt) {
        if (window.top != window.self) {
            window.parent.tool.alertError(youdao(txt), youdao(sub_txt), "error");
        } else {
            swal(youdao(txt), youdao(sub_txt), "error");
        }
    },
    alertWarning: function (txt, sub_txt) {
        if (window.top != window.self) {
            window.parent.tool.alertWarning(youdao(txt), youdao(sub_txt), "warning");
        } else {
            swal(youdao(txt), youdao(sub_txt), "warning");
        }
    },
    alertConfirm: function (txt, sub_txt, callback, callback2) {
        if (window.top != window.self) {
            window.parent.tool.alertConfirm(youdao(txt), youdao(sub_txt), callback, callback2);
        } else {
            swal({
                title: txt,
                text: sub_txt,
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                closeOnConfirm: false
            }, function (isConfirm) {
                if (!isIE8) {
                    swal.close();
                }
                if (isConfirm) {
                    callback();
                } else {
                    if (callback2 != null && callback2 != "") {
                        callback2();
                    }
                }
            });
        }
    },
    /**
     * 删除全部数据
     * @param el
     */
    doRemoveAll: function (el) {
        var totalRows = $("#totalRows").val();
        tool.alertConfirm('确定要删除本次查询的' + totalRows + '条记录?', '删除后将无法恢复，请谨慎操作！', function () {
            tool.setWaitForResponseStatus($(el));
            var form_element = $(el).parents('.form-horizontal');
            var data = form_element.serialize();
            tool.deleteAllData(el, data);
        });
    },
    /**
     * 删除全部数据
     * @param el
     * @param data
     */
    deleteAllData: function (el, data) {
        var form_element = $(el).parents('.form-horizontal');
        var url = form_element.attr("data-action");
        if (url.indexOf("action") < 0) {
            url = url.substr(0, url.lastIndexOf("/")) + "/removeAll";
        } else {
            url = url.substr(0, url.indexOf("-")) + "-deleteAllData.action";
        }
        $.ajax({
            url: tool.initParams(url),
            type: "post",
            data: data,
            dataType: "json",
            timeout: 1000 * 60,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                tool.ajaxError(XMLHttpRequest, textStatus, errorThrown);
            },
            success: function (data) {
                tool.removeWaitForResponseStatus();
                data = eval(data);
                if (data.oper_res) {
                    tool.doSearch(el);
                } else {
                    setTimeout('tool.alertError("操作失败!","' + data.oper_msg + '")', 100);
                }
            }
        });
    },
    /**
     * 删除数据
     * @param el list删除按钮 | 不可为空
     * @param callback 回调函数
     * @param detip 修改小标题提示
     */
    doRemove: function (el, callback, detip) {
        var form_element = $(el).parents('.form-horizontal');
        var ids = tool.getChoseData(form_element);
        if (detip == null || detip == '') {
            detip = "删除后将无法恢复，请谨慎操作！";
        }
        if (!isBlank(ids)) {
            tool.alertConfirm('确定要删除勾选的数据吗?', detip, function () {
                tool.setWaitForResponseStatus($(el));
                tool.deleteData(form_element, {"wid": ids}, callback);
            })
        } else {
            tool.alertWarning('请选择要删除的数据!', '请在下方列表中勾选要删除的数据');
        }
    },
    /**
     * 删除数据
     * @param el list删除按钮 | 不可为空
     * @param callback 回调函数
     * @param detip 修改小标题提示
     */
    doRemoveDepart: function (el, callback, detip) {
        var form_element = $(el).parents('.form-horizontal');
        var ids = tool.getChoseData(form_element);
        if (detip == null || detip == '') {
            detip = "删除后将无法恢复，请谨慎操作！";
        }
        if (!isBlank(ids)) {
            tool.alertConfirm('确定要删除勾选的数据吗?', detip, function () {
                tool.setWaitForResponseStatus($(el));
                tool.deleteData(form_element, {"wid": ids, "nd": $('#nd').val()}, callback);
            })
        } else {
            tool.alertWarning('请选择要删除的数据!', '请在下方列表中勾选要删除的数据');
        }
    },
    /**
     * 根据id删除数据
     * @param el 删除按钮 | 不可为空 | 示例 this
     * @param id 要删除数据的id
     * @param callback 回调函数
     */
    deleteDataById: function (el, id, callback) {
        tool.deleteData($(el).parents('.form-horizontal'), {"wid": id}, callback);
    },
    /**
     * 删除数据
     * @param $form 表单对象 | 不可为空
     * @param ajax_data 参数 | 不可为空 | 示例 字符串或者json
     * @param callback 回调函数
     */
    deleteData: function ($form, ajax_data, callback) {
        var url = $form.attr("data-action");
        if (url.indexOf("action") < 0) {
            if (url.indexOf("/s/system") > 0) {
                url = url.substring(0, url.indexOf('/s/') + 10) + url.substring(url.indexOf('/s/') + 10).substring(0, url.substring(url.indexOf('/s/') + 10).indexOf("/"));
            } else if (url.indexOf("/s/id") > 0) {
                url = url.substring(0, url.indexOf('/s/') + 6) + url.substring(url.indexOf('/s/') + 6).substring(0, url.substring(url.indexOf('/s/') + 6).indexOf("/"));
            } else {
                url = url.substring(0, url.indexOf('/s/') + 7) + url.substring(url.indexOf('/s/') + 7).substring(0, url.substring(url.indexOf('/s/') + 7).indexOf("/"));
            }
            url = url + "/remove";
        } else {
            url = url.substr(0, url.indexOf("-")) + "-remove.action";
        }
        $.ajax({
            url: tool.initParams(url),
            type: "post",
            data: ajax_data,
            dataType: "json",
            timeout: 1000 * 5,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                tool.ajaxError(XMLHttpRequest, textStatus, errorThrown);
            },
            success: function (data) {
                tool.removeWaitForResponseStatus();
                data = eval(data);
                if (data.oper_res) {
                    var $delTr = $("#tr_" + ajax_data.wid.replace(/,/g, ',#tr_'));
                    $delTr.find(".btn").css("border-color", "#fff");
                    $delTr.addClass("isdelete").find("td").css({"background-color": "#FF3300"}).fadeOut(1000, function () {
                        $(this).remove();
                    });
                    if (isFunction(callback)) {
                        callback();
                    }
                } else {
                    setTimeout('tool.alertError("操作失败!","' + data.oper_msg + '")', 100);
                }
            }
        });
    },
    /**
     * 查询
     * @param el 查询按钮
     * @param callback 回调函数
     */
    doSearch: function (el, parm, callback) {
        var $form = $(el).parents('.form-horizontal');
        // var $currentPageno = $form.find('#yspager_currentPageno');
        // if ($currentPageno.length > 0) {
        //     $currentPageno.val(1);
        // }
        tool.submitForm($form, parm, callback);
    },
    /**
     * 做List查询条件保存
     * @param el
     * @param parm
     * @param callback
     */
    doSaveSearch: function (el, parm, callback) {
        var $form = $(el).parents('.form-horizontal');
        var url = "/pros/s/ajax/saveSearchData";
        var dataurl = $($form).attr("data-action");
        var sqwid = dataurl.substring(dataurl.indexOf("biz") + 4, dataurl.indexOf("?jddes"));
        var fromdata = $form.serialize();
        $.ajax({
            url: tool.initParams(url),
            cache: false,
            type: "post",
            data: {"fromdata": fromdata, "sqwid": sqwid},
            dataType: "html",
            timeout: 1000 * 30,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                tool.ajaxError(XMLHttpRequest, textStatus, errorThrown);
            },
            success: function (data) {
                data = eval("(" + data + ")");

                if (data.oper_res) {
                    setTimeout('tool.alertSuccess("' + data.oper_msg + '")', 100);

                } else {
                    setTimeout('tool.alertError("操作失败!","' + data.oper_msg + '")', 100);
                }
            }
        });
    },


    /**
     * 初始化表格排序
     * 注: 需要排序的表格中请在class上添加table-order
     */
    initOrderTables: function () {
        $(".table-order").each(function () {
            tool.initOrderTable($(this));
        });
    },
    /**
     * 初始化表格排序功能
     * @param $table 表格对象
     */
    initOrderTable: function ($table) {
        $table.find("thead tr th[data-order-name]").each(function () {
            if ($(this).attr("data-is-init") == "1") {

            } else {
                $(this).attr("data-is-init", "1");
                $(this).addClass("poi");
                $(this).off("click").click(function () {
                    var order_type = $(this).attr("data-order-type");
                    if (isBlank(order_type)) {
                        order_type = "desc";
                    }
                    if (order_type == "asc") {
                        order_type = "desc";
                    } else if (order_type == "desc") {
                        order_type = "asc";
                    }
                    var form_element = $(this).parents('.form-horizontal');
                    form_element.find("#orderField").val($(this).attr("data-order-name"));
                    form_element.find("#orderType").val(order_type);
                    tool.submitForm(form_element);
                });
            }
        });
        //标记排序状态
        $table.find("th[data-order-name]").addClass('sort-null').attr('title', '点击标题排序');
        var _order = $('#orderField').val();
        var _orderType = $('#orderType').val();
        var order_icon;
        if (!isBlank(_order)) {//如果排序信息不为空
            var $th = $table.find('thead tr th[data-order-name="' + _order + '"]');
            if (_orderType == "asc") {
                order_icon = 'sort-asc';
            } else if (_orderType == "desc") {
                order_icon = 'sort-desc';
            }
            $th.attr("data-order-type", _orderType);
            $th.addClass(order_icon).removeClass('sort-null');
        }
    },
    /**
     * 检查subview容器是否存在,如果不存在则根据当前所在form生成
     * @param $form_element form对象 | 不可为空
     * @param subview_box 子窗口id | 可为空
     * @returns {*} subview_box子窗口id
     */
    initSubViewBox: function ($form_element, subview_box) {
        if (isBlank(subview_box)) {
            var url = $form_element.attr("data-action");
            if (url.indexOf("?") > -1) {
                url = url.substring(url.indexOf(basePath), url.indexOf("?"));
            }
            subview_box = "subview-box-" + url.replace(/\//g, "-").replace(/\./g, "-").replace(/:/g, "-");
        }
        if ($("#" + subview_box).length == 0) {
            $form_element.parent().append("<div id=\"" + subview_box + "\" class=\"no-display subview-box\"><div class=\"col-xs-12\"></div></div>");
        }
        return subview_box;
    },
    /**
     * 新增一行 (可编辑表格)
     * @param el 新增按钮 | 不可为空 | 示例 this
     */
    addRow: function (el) {
        el = $(el).parents('.form-horizontal');
        var frist_row, model_row = el.find('table:first tbody tr:last-child');//使用最后一行作为模板
        if (model_row.length > 0) {//表格中无数据,使用传入格式生成
            frist_row = el.find('table:first tbody tr:eq(0)');
            frist_row.before("<tr name=\"new-row\">" + model_row.html() + "</tr>");
        } else {
            el.find('table:first tbody').html('<tr name="new-row">' + el.find('#data-model tbody tr:eq(0)').html() + '</tr>');
        }
        frist_row = el.find('table:first tbody tr:eq(0)');
        var i = 0;
        frist_row.find("td").each(function () {
            var el = $(this);
            if (i > 0) {
                if (el.data("edit") == true) {
                    if (!isBlank(el.data("url"))) {//链接
                        el.find("a").hide();
                        el.append("<input type=\"text\" data-name=\"" + el.data("name") + "\" class=\"form-control\" style=\"width:100%;\"/>");
                    } else if (!isBlank(el.data("table-name"))) {//select
                        el.html("<select data-table-name=\"" + tool.getString(el.data("table-name")) + "\" " +
                            "data-field-id=\"" + tool.getString(el.data("field-id")) + "\" " +
                            "data-field-name=\"" + tool.getString(el.data("field-name")) + "\" " +
                            "data-field-up-id=\"" + tool.getString(el.data("field-up-id")) + "\" " +
                            "data-file-up-val=\"" + tool.getString(el.data("file-up-val")) + "\" " +
                            "data-file-query=\"" + tool.getString(el.data("file-query")) + "\" " +
                            "data-query-val=\"" + tool.getString(el.data("query-val")) + "\" " +
                            "data-name=\"" + el.data("name") + "\" " +
                            "style=\"width:100%;\"" +
                            "class=\"form-control select2-auto\"></select>");
                    } else if (el.data("element-type") == "datepicker") {
                        el.html("<input type=\"text\" data-name=\"" + el.data("name") + "\" class=\"form-control\" data-element-type=\"datepicker\" style=\"width:100%;\"/>");
                    } else {
                        el.html("<input type=\"text\" data-name=\"" + el.data("name") + "\" class=\"form-control\" style=\"width:100%;\"/>");
                    }
                }
            } else {
                el.html("");
            }
            i++;
        });
        //绑定事件
        frist_row.find(".edit-row").off("click").click(function () {
            tool.edit_row($(this));
        });
        frist_row.find(".save-row").off("click").click(function () {
            tool.save_row($(this));
        });
        frist_row.find(".del-row").off("click").click(function () {
            tool.del_row($(this));
        });

        //初始化插件
        frist_row.find(".edit-row").addClass("dn").parents("tr").find(".save-row").removeClass("dn");
        Main.initForm(frist_row);
    },
    /**
     * 初始化编辑按钮(for可编辑表格)
     */
    initEditRow: function () {
        var $editRow = $(".edit-row");
        if ($editRow.length) {
            $editRow.each(function () {
                $(this).off("click").click(function () {
                    tool.edit_row($(this));
                });
            });
        }
    },
    /**
     * 初始化保存按钮(for可编辑表格)
     */
    initSaveRow: function () {
        var $saveRow = $(".save-row");
        if ($saveRow.length) {
            $saveRow.each(function () {
                $(this).off("click").click(function () {
                    tool.save_row($(this));
                });
            });
        }
    },
    /**
     * 初始化删除按钮(for可编辑表格)
     */
    initDelRow: function () {
        var $delRow = $(".del-row");
        if ($delRow.length) {
            $delRow.each(function () {
                $(this).off("click").click(function () {
                    tool.del_row($(this));
                });
            });
        }
    },
    /**
     * 保存 (for 可编辑表格)
     * @param el
     */
    save_row: function (el) {
        el = el.parents("tr");
        var url = "";
        var form_element = el.parents('.form-horizontal');
        if (el.validationEngine('validate')) {
            url = form_element.attr("data-action");
            //spring mvc
            if (url.indexOf("action") < 0) {
                if (url.indexOf("/s/system") > 0) {
                    url = url.substring(0, url.indexOf('/s/') + 10) + url.substring(url.indexOf('/s/') + 10).substring(0, url.substring(url.indexOf('/s/') + 10).indexOf("/"));
                } else if (url.indexOf("/s/id") > 0) {
                    url = url.substring(0, url.indexOf('/s/') + 6) + url.substring(url.indexOf('/s/') + 6).substring(0, url.substring(url.indexOf('/s/') + 6).indexOf("/"));
                } else {
                    url = url.substring(0, url.indexOf('/s/') + 7) + url.substring(url.indexOf('/s/') + 7).substring(0, url.substring(url.indexOf('/s/') + 7).indexOf("/"));
                }
                url = url + "/save";
            } else {
                url = url.substr(0, url.indexOf("-")) + "-saveData.action";
            }
            var backdrop = $('.ajax-white-backdrop');
            $(".main-container").append('<div class="ajax-white-backdrop"></div>');
            backdrop.show();
            el.find("input,select").each(function () {
                $(this).attr("name", $(this).data("name"));
            });
            var data;
            if (el.find("input[name='wid']:checked").length != 0) {//如果选中
                data = el.find("input,select").serialize();
            } else {
                if (el.find("input[name='wid']").length > 0) {//修改
                    data = el.find("input,select").serialize() + "&wid=" + el.find("input[name='wid']").val();
                } else {
                    data = el.find("input,select").serialize();
                }
            }
            $.ajax({
                url: tool.initParams(url),
                type: "POST",
                data: data,
                dataType: "json",
                timeout: 1000 * 10,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    tool.ajaxError(XMLHttpRequest, textStatus, errorThrown, backdrop);
                },
                success: function (data) {
                    el.find(".save-row").addClass("dn").parents("tr").find(".edit-row").removeClass("dn");
                    if (!isBlank(data)) {
                        //noinspection JSUnresolvedVariable
                        if (data.oper_res == "success") {//成功
                            //如果tr[id]为空 则表示新增
                            if (el.attr("name") == "new-row") {//新增
                                el.attr("id", "tr_" + data.data.wid);
                                el.find("td:eq(0)").html("<div class=\"checkbox-table\"><label><input data-name=\"wid\" type=\"checkbox\" name=\"selectNode\" class=\"grey foocheck\" id=\"" + data.data.wid + "\" value=\"" + data.data.wid + "\"></label></div>");
                                el.removeAttr("name");
                                el.find(".del-row").attr("data-wid", data.data.wid);
                                Main.initForm(el);
                            }
                            el.find("td").each(function () {
                                if (!isBlank($(this).attr("data-name")) && $(this).attr("data-name") != "wid") {
                                    if (!isBlank($(this).data("url"))) {//链接
                                        //a连接 默认使用修改方法
                                        $(this).html("<a onclick=\"editDataById(this,'" + data.data.wid + "')\" href=\"javascript:void(0)\">" + $(this).find("input").val() + "</a>");
                                    } else {
                                        if ($(this).find("input").length > 0) {
                                            $(this).html($(this).find("input").val());
                                        } else if ($(this).find("select").length > 0) {
                                            $(this).html($(this).find("select").find("option:selected").text());
                                        }
                                    }
                                }
                            });
                        } else {
                            tool.alertWarning(data.open_msg);
                        }
                    }
                    backdrop.remove();
                }
            });
        }
    },
    /**
     * 删除行(for 可编辑表格)
     * @param el
     */
    del_row: function (el) {
        tool.deleteData(el.parents('.form-horizontal'), {"wid": el.data("wid")});
    },
    edit_row: function (el_btn) {
        $(el_btn.parents("tr").find("td")).each(function () {
            var el = $(this);
            if (el.data("edit") == true) {
                if (!isBlank(el.data("url"))) {//链接
                    el.find("a").hide();
                    el.append("<input type=\"text\" data-name=\"" + el.data("name") + "\" class=\"form-control\" value=\"" + trim(el.find("a").html()) + "\" style=\"width:100%;\"/>");
                } else if (!isBlank(el.data("table-name"))) {//select
                    el.html("<select data-table-name=\"" + tool.getString(el.data("table-name")) + "\" " +
                        "data-field-id=\"" + tool.getString(el.data("field-id")) + "\" " +
                        "data-field-name=\"" + tool.getString(el.data("field-name")) + "\" " +
                        "data-field-up-id=\"" + tool.getString(el.data("field-up-id")) + "\" " +
                        "data-file-up-val=\"" + tool.getString(el.data("file-up-val")) + "\" " +
                        "data-file-query=\"" + tool.getString(el.data("file-query")) + "\" " +
                        "data-query-val=\"" + tool.getString(el.data("query-val")) + "\" " +
                        "data-name=\"" + el.data("name") + "\" " +
                        "data-val=\"" + tool.getString(el.data("val")) + "\" style=\"width:100%;\"" +
                        "class=\"form-control select2-auto\"></select>");
                } else if (el.data("element-type") == "datepicker") {
                    el.html("<input type=\"text\" data-name=\"" + el.data("name") + "\" class=\"form-control\" data-element-type=\"datepicker\" value=\"" + trim(el.html()) + "\" style=\"width:100%;\"/>");
                } else {
                    el.html("<input type=\"text\" data-name=\"" + el.data("name") + "\" class=\"form-control\" value=\"" + trim(el.html()) + "\" style=\"width:100%;\"/>");
                }
            }
        });
        el_btn.addClass("dn").parents("tr").find(".save-row").removeClass("dn");
        Main.initForm(el_btn.parents("tr"));
    },

    /**
     * 初始化文件上传
     * @param el file element
     * @param url url
     * @param data 附加数据
     * @param auto_upload 是否自动上传
     * @param fileTypeExts 支持的格式
     * @param queueSizeLimit 上传文件数量限制
     * @param onSelect 选择文件事件
     * @param onUploadSuccess 文件上传成功事件
     * @param onQueueComplete 列队所有文件上传完毕
     * @param fileSizeLimit 上传文件大小限制
     * @param uploadfileQueue 上传列队显示容器
     * @param buttonText 上传按钮文字
     * @param onUploadStart 文件开始上传
     */
    initFileUpload: function (el, url, data, auto, fileTypeExts, queueSizeLimit, onSelect, onUploadSuccess,
                              onQueueComplete, fileSizeLimit, uploadfileQueue, buttonText, onUploadStart, buttonClass) {
        var config = {};
        config.auto = auto;
        if (isBlank(fileSizeLimit)) {
            config.fileSizeLimit = '20MB';
        } else {
            config.fileSizeLimit = fileSizeLimit;
        }
        if (!isBlank(uploadfileQueue)) {
            config.queueID = uploadfileQueue;
        }
        if (isBlank(buttonClass)) {
            config.buttonClass = 'btn btn-sm btn-info';
        } else {
            config.buttonClass = buttonClass;
        }
        if (isBlank(buttonText)) {
            config.buttonText = '选择文件 <i class=\"fa fa-plus\"></i>';
        } else {
            config.buttonText = buttonText;
        }
        config.selector = el;
        config.formData = data;
        config.onSelect = onSelect;
        config.onQueueComplete = onQueueComplete;
        config.removeCompleted = true;
        if (!tool.supportHtml5()) {//IE8/9不支持html5方式上传,需要用flash
            config.onUploadStart = onUploadStart;
            config.onUploadSuccess = onUploadSuccess;
            config.onUploadError = function (file, errorCode, errorMsg, errorString) {
                try {
                    subPage.onUploadError();
                } catch (ex) {
                }
            }
            config.onInit = function () {
                if (!tool.has_flash()) {
                    swal({
                        title: "缺少Flash插件",
                        type: 'warning',
                        text: "您未安装Flash控件，无法上传文件！请使用Chrome/Firefox/IE10+浏览器，或<a target='_blank' href='https://get.adobe.com/flashplayer/?loc=cn'>点此</a>安装FLASH控件重启浏览器后重试。",
                        html: true,
                        showConfirmButton: false
                    });
                }
            }
            if (isBlank(url)) {
                config.uploader = basePath + "/fileUpload";
            } else {
                config.uploader = url;
            }
            config.fileTypeDesc = '支持的格式：';
            config.fileTypeExts = fileTypeExts;
            config.width = 82;
            config.height = 30;
            config.swf = basePath + '/resources/plugins/uploadify/uploadify.swf';
            config.onSelectError = function (file, errorCode, errorMsg) {
                switch (errorCode) {
                    case -100:
                        tool.alertWarning("上传的文件数量已经超出系统限制！");
                        break;
                    case -110:
                        tool.alertWarning("文件大小超出系统限制的" + fileSizeLimit + "！");
                        break;
                    case -120:
                        tool.alertWarning("文件大小异常！");
                        break;
                    case -130:
                        tool.alertWarning("文件类型不正确！");
                        break;
                }
            }
            config.onFallback = function () {
                swal({
                    title: "缺少Flash插件",
                    type: 'warning',
                    text: "您未安装Flash控件，无法上传文件！请使用Chrome/Firefox/IE10+浏览器，或<a target='_blank' href='https://get.adobe.com/flashplayer/?loc=cn'>点此</a>安装FLASH控件重启浏览器后重试。",
                    html: true,
                    showConfirmButton: false
                });
            }
            try {
                if (!isBlank(config.selector)) {
                    $(config.selector).uploadify(config);
                }
            } catch (e) {
                console.log(e);
            }
        } else {
            //即将上传
            config.onUpload = onUploadStart;
            //上传完毕
            config.onUploadComplete = onUploadSuccess;
            if (isBlank(url)) {
                config.uploadScript = basePath + "/fileUpload";
            } else {
                config.uploadScript = url;
            }
            if (isNotBlank(fileTypeExts)) {
                fileTypeExts = tool.extensionToContentTypes(fileTypeExts);
            }
            config.fileType = fileTypeExts;
            config.onFallback = function () {

            }
            // config.fileType = ['application/x-img', 'application/x-dbf', 'application/x-zip-compressed'];

            try {
                if (!isBlank(config.selector)) {
                    $(config.selector).uploadifive(config);
                }
            } catch (e) {
                console.log(e);
            }
        }
    },
    /**
     * 文件拓展名(Extension)转Content-Type(Mime-Type)
     * @param extensions
     */
    extensionToContentTypes: function (extensions) {
        extensions = extensions.split(';');
        var contentType = [];
        var temp = null;
        for (var i = 0; i < extensions.length; i++) {
            temp = CONTENT_TYPE[extensions[i].replace('*', '')];
            if (isNotBlank(temp)) {
                contentType.push(temp);
            }
        }
        return contentType;
    },
    /**
     * 文件拓展名(Extension)转Content-Type(Mime-Type)
     * @param extension
     */
    extensionToContentType: function (extension) {
        return CONTENT_TYPE[extension];
    },
    /**
     * 触发开始上传
     * @param $el     */
    startUpload: function ($el) {
        if (!tool.supportHtml5()) {//IE8/9不支持html5方式上传,需要用flash
            $el.uploadify('upload', '*');
        } else {
            $el.uploadifive('upload');
        }
    },
    has_flash: function () {
        var isIE = !-[1,];
        if (isIE) {
            try {
                return !!new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
            }
            catch (e) {
            }
        } else {
            try {
                return !!navigator.plugins['Shockwave Flash'];
            }
            catch (e) {
            }
        }
        return false;
    },
    /**
     * 初始化文件上传
     * @param object
     */
    initFileUploadByConfig: function (object) {
        //按钮样式
        if (isBlank(object.buttonClass)) {
            object.buttonClass = 'btn btn-sm btn-info';
        }
        //按钮文字
        if (isBlank(object.buttonText)) {
            object.buttonText = '选择文件 <i class=\"fa fa-plus\"></i>';
        }
        //大小限制
        if (isBlank(object.fileSizeLimit)) {
            object.fileSizeLimit = '20MB';
        }
        object.removeCompleted = true;
        //是否自动上传
        if (isBlank(object.auto)) object.auto_upload = false;
        if (!tool.supportHtml5()) {//IE8/9不支持html5方式上传,需要用flash
            if (isBlank(object.uploader)) object.uploader = basePath + "/fileUpload";
            object.swf = basePath + '/resources/plugins/uploadify/uploadify.swf';
            if (isBlank(object.fileTypeDesc)) {
                object.fileTypeDesc = '支持的格式：';
            }
            if (isBlank(object.onSelectError)) {
                object.onSelectError = function (file, errorCode, errorMsg) {
                    switch (errorCode) {
                        case -100:
                            tool.alertWarning("上传的文件数量已经超出系统限制！");
                            break;
                        case -110:
                            tool.alertWarning("文件大小超出系统限制的" + fileSizeLimit + "！");
                            break;
                        case -120:
                            tool.alertWarning("文件大小异常！");
                            break;
                        case -130:
                            tool.alertWarning("文件类型不正确！");
                            break;
                    }
                }
            }
            if (isBlank(object.onFallback)) {
                object.onFallback = function () {
                    swal({
                        title: "缺少Flash插件",
                        type: 'warning',
                        text: "您未安装Flash控件，无法上传文件！请使用Chrome/Firefox/IE10+浏览器，或<a target='_blank' href='https://get.adobe.com/flashplayer/?loc=cn'>点此</a>安装FLASH控件重启浏览器后重试。",
                        html: true,
                        showConfirmButton: false
                    });
                }
            }
            try {
                if (!isBlank(object.selector)) {
                    $(object.selector).uploadify(object);
                }
            } catch (e) {
                console.log(e);
            }
        } else {
            //服务器处理url
            if (isBlank(object.uploader)) {
                object.uploadScript = basePath + "/fileUpload";
            } else {
                object.uploadScript = object.uploader;
            }
            //即将上传
            object.onUpload = object.onUploadStart;
            //上传完毕
            object.onUploadComplete = object.onUploadSuccess;
            if (isNotBlank(object.fileTypeExts)) {
                object.fileType = tool.extensionToContentTypes(object.fileTypeExts);
            }
            if (isBlank(object.onFallback)) {
                object.onFallback = function () {
                    // tool.alertWarning("您未安装FLASH控件，无法上传文件！请安装FLASH控件后再试。");
                }
            }
            try {
                if (!isBlank(object.selector)) {
                    $(object.selector).uploadifive(object);
                }
            } catch (e) {
                console.log(e);
            }
        }
    },
    initPageHeight: function (el) {
        var mainheight = $(el).contents().find('body').height();
        $(el).height(mainheight * 0.8);
    },
    /**
     * 打开modal窗口
     * @param options
     * @modaltitle 模态框标题
     * @returns {*|jQuery|HTMLElement}
     */
    openModal: function (options, width, isiframe, callback, height, callback2, modaltitle) {
        if (height == null || height == '') {
            height = $('.J_mainContent', window.parent.document).height() - 170;
        }
        if (width == "" || width == null) {
            width = "";
        }
        if (modaltitle == "" || modaltitle == null) {
            modaltitle = "&nbsp;";
        }
        if (options.remote.indexOf('jd=') == -1) {
            options.remote = tool.initParams(options.remote);
        }
        var modal_id = tool.randomString(15);
        if (isiframe == null || isiframe) {
            var iframeid = tool.randomString(15);
            var html = '<div class="modal fade" id="' + modal_id + '" tabindex="-1" role="dialog" aria-hidden="true">' +
                '<div class="modal-dialog modal-lg" style="width:' + width + '">' +
                '<div class="modal-content">' +
                '<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title">' + modaltitle + '</h4></div>' +
                '<div class="modal-body">';
            html += '<iframe id="' + iframeid + '" width="100%" height="' + height + '" frameborder="0" src="' + options.remote + '"></iframe>';
            html += '</div></div></div>';
            $('body').append(html);
            var $modal = $('#' + modal_id);
            $modal.modal({backdrop: 'static', keyboard: false}).modal('show').on('shown.bs.modal', function (e) {
                // Main.initTabModel($modal);
                $modal.removeAttr('tabindex');
            }).on('hidden.bs.modal', function (e) {
                // 关闭时销毁
                if (isFunction(callback2)) {
                    callback2();
                }
                $modal.remove();
            });

        } else {
            var html = '<div class="modal fade" id="' + modal_id + '" tabindex="-1" role="dialog" aria-hidden="true">' +
                '<div class="modal-dialog modal-lg" style="width:' + width + '">' +
                '<div class="modal-content" style="display: table;width: 100%;">';
            $.ajax({
                url: options.remote,
                cache: false,
                type: "post",
                dataType: "html",
                data: options.data,
                timeout: 1000 * 15,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    tool.ajaxError(XMLHttpRequest, textStatus, errorThrown);
                },
                success: function (data) {
                    var $data = $(data);
                    //将本页面url放到form的data-action中
                    if ($data.find(".form-horizontal").length > 0) {
                        if (isBlank($data.find(".form-horizontal").attr("data-action"))) {
                            $data.find(".form-horizontal").attr("data-action", options.remote);
                        }
                        if (options.remote.indexOf("action") < 0) {//spring mvc
                            $data.find(".form-horizontal").find("#yspager_currentPageno").attr("name", "currentPageno");
                            $data.find(".form-horizontal").find("#eachPageRows").attr("name", "eachPageRows");
                        }
                    } else {
                        data = '<div><form class="form-horizontal" data-action="' + options.remote + '">' + data + '</form></div>';
                        $data = $(data);
                    }
                    if ($data.find('.modal-header').length <= 0) {
                        html += '<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 class="modal-title">' + modaltitle + '</h4></div>'
                    }
                    if ($data.find('.modal-body').length <= 0) {
                        html += '<div class="modal-body">' + $data.find('.form-horizontal').prop('outerHTML') + '</div>';
                    } else {
                        html += $data.find('.form-horizontal').prop('outerHTML');
                    }
                    // if ($data.find('.modal-footer').length <= 0) {
                    // html += '<div class="modal-footer"><button type="button" class="btn btn-default btn-sm" data-dismiss="modal">关闭</button></div>';
                    // }
                    html += '</div></div></div>'
                    $('body').append(html);
                    var $modal = $('#' + modal_id);
                    $modal.modal('show').on('shown.bs.modal', function (e) {
                        Main.initTabModel($modal);
                        $modal.removeAttr('tabindex');
                    }).on('hidden.bs.modal', function (e) {
                        //关闭前执行方法
                        if (isFunction(callback2)) {
                            callback2();
                        }

                        // 关闭时销毁
                        $modal.remove();
                    });
                    if (isFunction(callback)) {
                        callback();
                    }
                    try {
                        getUserChosoe();//模态框弹出后调用国际化
                    } catch (e) {
                    }

                }
            });
        }
        return modal_id;
    },
    /**
     * 打开静态模态框
     * @param modalId 模态框id
     * @param title 标题
     * @param functionName 确定回调函数
     */
    openModalStatic: function (modalId, title, functionName) {
        var message = '<div class="pl30 pr30"><form role="form" class="form-horizontal"><div class="row">' + $('#' + modalId).html() + '</div></form></div>';
        window.parent.bootbox.dialog({
            title: title,
            className: '',
            message: message,
            buttons: {
                copy: {
                    label: "确定",
                    className: 'btn-sm btn-green',
                    callback: function () {
                        functionName();
                    }
                },
                close: {
                    label: "关闭",
                    className: "btn-default btn-sm",
                    callback: function () {
                    }
                }
            }
        });
    },
    openModalStaticNoOK: function (modalId, title) {
        var message = '<div class="pl30 pr30"><form role="form" class="form-horizontal"><div class="row">' + $('#' + modalId).html() + '</div></form></div>';
        bootbox.dialog({
            title: title,
            className: '',
            message: message,
            buttons: {
                close: {
                    label: '关闭',
                    className: "btn-default btn-sm",
                    callback: function () {
                    }
                }
            }
        });
    },
    openModalStaticFor: function (modalId, title, functionName) {


    },
    modal: function ($el, options, show, shown, hide, hidden) {
        window.parent.tool.modal($el, options, show, shown, hide, hidden);
    },
    /**
     * 删除 For 可编辑表格
     * @param el 按钮 this
     */
    removeDateForEditTable: function (el) {
        $(el).parents('tr').remove();
    },

    /**
     * 清楚input数据
     * @param el
     */
    clearinput: function (el) {
        if ($(el).prev().attr("readonly") != 'readonly') {
            $(el).prev().val("");
            $(el).hide();
        }
    },
    /**
     * 文本域输入方法。
     */
    checkMaxInput: function (obj, maxLen) {
        if (obj == null || obj == undefined || obj == "") {
            return;
        }
        if (maxLen == null || maxLen == undefined || maxLen == "-1") {
            $(obj).next().next().remove();
        }
        var strResult;
        var $obj = $(obj);
        var newid = $obj.attr("id") + "msg";
        if (obj.value.length > maxLen) {
            obj.value = obj.value.substring(0, maxLen);
        } else {
            $("#" + newid).html(obj.value.length)
        }
    },

    /**
     * 删除 For 可编辑表格
     * @param el 按钮 this
     */
    removeDateForEditTable: function (el) {
        $(el).parents('tr').remove();
    },
    upDateForEditTable: function (el) {
        var f = $(el).parents('tbody').find('tr:first').find('input:first').attr('name');
        if (f == $(el).parents('tr').find('input:first').attr('name')) {
            return false;
        }
        var index = $(el).parents('tr').find('input:first').attr('name');
        index = index.substring(index.indexOf('[') + 1, index.indexOf(']'));

        var p_index = $(el).parents('tr').prev('tr').find('input:first').attr('name');
        p_index = p_index.substring(p_index.indexOf('[') + 1, p_index.indexOf(']'));
        $(el).parents('tr').prev('tr').find('input,select').each(function () {
            $(this).attr('name', $(this).attr('name').replace('[' + p_index + ']', '[' + index + ']'));
            $(this).attr('id', $(this).attr('name'));
        });

        $(el).parents('tr').find('input,select').each(function () {
            $(this).attr('name', $(this).attr('name').replace('[' + index + ']', '[' + p_index + ']'));
            $(this).attr('id', $(this).attr('name'));
        });
        var t_htm = $(el).parents('tr').prop('outerHTML');

        $(el).parents('tr').prev('tr').before(t_htm);
        $(el).parents('tr').prev('tr').prev('tr').find('input').each(function (i) {
            $(this).val($(el).parents('tr').find('input').eq(i).val());
        });
        $(el).parents('tr').prev('tr').prev('tr').find('select').each(function (i) {
            $(this).val($(el).parents('tr').find('select').eq(i).val());
        });
        tool.removeDateForEditTable(el);
    },
    downDateForEditTable: function (el) {
        var f = $(el).parents('tbody').find('tr:last').find('input:first').attr('name');
        if (f == $(el).parents('tr').find('input:first').attr('name')) {
            return false;
        }
        var index = $(el).parents('tr').find('input:first').attr('name');
        index = index.substring(index.indexOf('[') + 1, index.indexOf(']'));

        var n_index = $(el).parents('tr').next('tr:first').find('input:first').attr('name');
        n_index = n_index.substring(n_index.indexOf('[') + 1, n_index.indexOf(']'));
        $(el).parents('tr').next('tr:first').find('input,select').each(function () {
            $(this).attr('name', $(this).attr('name').replace('[' + n_index + ']', '[' + index + ']'));
            $(this).attr('id', $(this).attr('name'));
        });

        $(el).parents('tr').find('input,select').each(function () {
            $(this).attr('name', $(this).attr('name').replace('[' + index + ']', '[' + n_index + ']'));
            $(this).attr('id', $(this).attr('name'));
        });
        var t_htm = $(el).parents('tr').prop('outerHTML');

        $(el).parents('tr').next('tr:first').after(t_htm);
        $(el).parents('tr').next('tr:first').next('tr:first').find('input').each(function (i) {
            $(this).val($(el).parents('tr').find('input').eq(i).val());
        });
        $(el).parents('tr').next('tr:first').next('tr:first').find('select').each(function (i) {
            $(this).val($(el).parents('tr').find('select').eq(i).val());
        });
        tool.removeDateForEditTable(el);
    },
    /**
     * 随即产生指定长度字符串
     * @param len
     * @returns {string}
     */
    randomString: function (len) {
        len = len || 32;
        var $chars = 'ABCDEFGHJKMINOPQRSTUVWXYZabcdefhijkminopqrstuwxyz';
        var maxPos = $chars.length;
        var pwd = '';
        for (var i = 0; i < len; i++) {
            pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
        }
        return pwd;
    },
    /**
     * 获取字符串,如果是undefined 返回 ""
     * @param str
     * @returns {*}
     */
    getString: function (str) {
        if (isBlank(str)) {
            str = "";
        }
        return str;
    },
    //兼容上个框架方法
    /**
     * 保存
     * @param el form中的一个对象 (this)
     */
    submit_save: function (el) {
        tool.saveData(el);
    },
    /**
     * 查询
     * @param el form中的一个对象 (this)
     * @param callback 回调函数
     */
    super_doSearch: function (el, parm, callback) {
        tool.doSearch(el, parm, callback);
    },
    /**
     * 修改
     * @param el form中的一个对象 (this)
     */
    doModify: function (el) {
        tool.editData(el);
    },
    /**
     * 打开窗口
     * @param el form中的一个对象 (this)
     * @param url url
     * @param name 标签页名称
     * @param showLoading 是否显示loading框,默认显示
     */
    openview: function (el, url, name, showLoading) {
        tool.openSubview(url, null, tool.getTabName(el, name), showLoading);
    },
    /**
     * 打开报表
     * @param el this
     * @param url url
     * @param name 标签页名称
     */
    openReport: function (el, url, name) {
        tool.openSubview(url, null, tool.getTabName(el, name), false);
    },
    openEntity: function (el, id) {
        tool.editDataById(el, id);
    },
    /**
     * 重置
     * @param el form中的一个对象 (this)
     */
    super_reset: function (el) {
        tool.resetForm(el);
    },
    /**
     * 下载文件
     * @param path
     */
    downloadfile: function (path) {
        if (path.indexOf('.jpg') > -1 || path.indexOf('.png') > -1 || path.indexOf('.jpeg') > -1 || path.indexOf('.gif') > -1) {
            tool.previewImageByPath(path);
        } else {
            window.parent.tool.downloadfile(path);
        }
    },
    /**
     * 加密url，返回带加密串的新url
     * @param url
     * @returns {*}
     */
    initParams: function (url) {
        // if (url == undefined) {
        //     return url;
        // }
        // $.ajax({
        //     type: "post",
        //     url: basePath + '/s/geturl',
        //     data: "url=" + url.replaceAll('&', 'jdand') + "&userloginid=" + tool.userloginid,
        //     async: false,
        //     error: function (XMLHttpRequest, textStatus, errorThrown) {
        //         if (textStatus == "timeout") {
        //             tool.alertWarning('请求超时!', '请稍后重试!');
        //         } else {
        //             tool.alertError(XMLHttpRequest.responseText);
        //         }
        //     },
        //     success: function (data) {
        //         if (url.indexOf('?') != -1) {
        //             url = url + '&jddes=' + data;
        //         } else {
        //             url = url + '?jddes=' + data;
        //         }
        //     }
        // });
        return url;
    },
    /**
     * 设置按钮为等待ajax响应状态,并禁止点击事件
     * @param $el 按钮 | jquery对象
     */
    setWaitForResponseStatus: function ($el) {
        tool.waitForResponseStatusBtn = $el;
        $el.attr('disabled', 'disabled').attr('data-text', $el.html()).html('<i class="fa fa-circle-o-notch fa-spin"></i> 处理中...');
        if ($el[0].nodeName == "A") {
            $el.attr('data-click', $el.attr('onclick')).attr('onclick', '');
        }
        var _i = $el.find('i');
        if (_i.length > 0) {
            _i.attr('data-btn-icon', _i.attr('class'));
            _i.attr('class', 'fa fa-circle-o-notch fa-spin');
        }
    },
    /**
     * 移除按钮等待ajax响应状态,并恢复点击事件
     * @param $el 按钮 | jquery对象
     */
    removeWaitForResponseStatus: function () {
        if (tool.waitForResponseStatusBtn != null && tool.waitForResponseStatusBtn.length > 0) {
            tool.waitForResponseStatusBtn.removeAttr('disabled', 'disabled').html(tool.waitForResponseStatusBtn.attr('data-text'));
            if (tool.waitForResponseStatusBtn[0].nodeName == "A") {
                tool.waitForResponseStatusBtn.attr('onclick', tool.waitForResponseStatusBtn.attr('data-click'));
            }
            var _i = tool.waitForResponseStatusBtn.find('i');
            if (_i.length > 0) {
                _i.attr('class', _i.attr('data-btn-icon'));
            }
            tool.waitForResponseStatusBtn = null;
        }
    },
    /**
     * 显示等待提示
     */
    showWaitTip: function () {
        $('.modal-backdrop, .wait-tip').removeClass('hide');
        //setTimeout('tool.setWaitTip()',2000);
    },
    setWaitTip: function () {
        $('.wait-tip .panel-body').html('<i class="fa fa-circle-o-notch fa-spin"></i> 数据量大,请耐心等待...');
    },
    /**
     * 隐藏等待提示
     */
    hideWaitTip: function () {
        $('.modal-backdrop, .wait-tip').addClass('hide');
        $('.wait-tip .panel-body').html('<i class="fa fa-circle-o-notch fa-spin"></i> 数据加载中,请稍候...');
    },
    isNotEmpty: function (val) {
        return !tool.isEmpty(val);
    },
    isEmpty: function (val) {
        if ((val == null || typeof(val) == "undefined") || (typeof(val) == "string" && val == "" && val != "undefined")) {
            return true;
        } else {
            return false;
        }
    },
    isDebug: function () {
        if (tool.isNotEmpty(tool.configDebug) && tool.configDebug == "true") {
            return true;
        } else {
            return false;
        }
    },
    //去除元素内所有内容 strIds："#id1,#id2,#id3"
    emptyHtml: function (strIds) {
        try {
            var ids = strIds.trim(",").split(",");
            $(ids).each(function () {
                var obj = $(tool.toString());
                if (obj.length > 0) {
                    $(obj).each(function () {
                        $(this).html("");
                    });
                } else {
                    obj.html("");
                }
            });
        } catch (ex) {
            if (tool.isDebug()) {
                throw new Error("js方法 - tool.emptyHtml(strIds),error！");
            }
        }
    },
    //去除元素的值 strIds："#id1,#id2,#id3"
    emptyValue: function (strIds) {
        try {
            var ids = strIds.trim(",").split(",");
            $(ids).each(function () {
                var obj = $(tool.toString());
                if (obj.length > 0) {
                    $(obj).each(function () {
                        $(this).val("");
                    });
                } else {
                    obj.val("");
                }
            });
        } catch (ex) {
            if (tool.isDebug()) {
                throw new Error("js方法 - tool.emptyValue(strIds),error!");
            }
        }
    },
    //去除Textarea内所有内容 strIds："#id1,#id2,#id3"
    emptyTextarea: function (strIds) {
        try {
            var ids = strIds.trim(",").split(",");
            $(ids).each(function () {
                var obj = $(tool.toString());
                if (obj.length > 0) {
                    $(obj).each(function () {
                        $(this).empty();
                        $(this).val("");
                    });
                } else {
                    obj.empty();
                    obj.val("");
                }
            });
        } catch (ex) {
            if (tool.isDebug()) {
                throw new Error("js方法 - tool.emptyTextarea(strIds) ,error！");
            }
        }
    },
    //审核数据调用方法
    report: function (el, ids, lcbm, type, glzd, con, json, thyj) {
        if (ids == null || ids == '') {
            var form_element = $(el).parents('.form-horizontal');
            var ids = tool.getChoseData(form_element);
            if (ids == null || ids == '') {
                tool.alertConfirm('未选中数据，是否确定操作所有数据?', '', function () {
                    $.post(tool.initParams(tool.procee + 's/biz/ajaxProcess/handle'), {
                        'handleids': 'allid', 'lcbm': lcbm, 'glzd': glzd, 'thyj': thyj,
                        'type': type, 'json': json, 'con': con
                    }, function (data) {
                        if (tool.iserror(data)) {
                            return false;
                        }
                        setTimeout('tool.alertSuccess_lc("' + data.jsonstr + '")', 100);
                        tool.submitForm($(el).parents('.form-horizontal'));
                    });
                });
                return false;
            }
        }
        $.post(tool.initParams(tool.procee + 's/biz/ajaxProcess/handle'), {
            'handleids': ids, 'lcbm': lcbm, 'glzd': glzd, 'json': json, 'thyj': thyj,
            'type': type, 'con': con
        }, function (data) {
            if (tool.iserror(data)) {
                return false;
            }
            setTimeout('tool.alertSuccess_lc("' + data.jsonstr + '")', 100);
            tool.submitForm($(el).parents('.form-horizontal'));
        });
    },
    //审核数据调用方法
    report_s: function (el, lcbm, type, glzd, con, json, thyj) {
        tool.report(el, null, lcbm, type, glzd, con, json, thyj);
    },
    /**
     * 审核全部数据调用方法
     * @param el 按钮对象 this
     * @param lcbm 流程名称
     * @param type 审核类型 AjaxProcessController中常量
     * @param glzd 关联字段
     */
    report_all: function (el, lcbm, type, glzd, con, json, thyj) {
        tool.report(el, 'allid', lcbm, type, glzd, con, json, thyj);
    },
    //填写审核意见时调用方法
    report_open: function (el, lcbm, type, glzd, con, json, isreq) {
        window.parent.tool.report_open(el, lcbm, type, glzd, con, json, isreq, tool);
    },
    //input页面填写审核意见时调用方法
    report_open_input: function (el, ids, lcbm, type, glzd, con, json, isreq) {
        window.parent.tool.report_open_input(el, ids, lcbm, type, glzd, con, json, isreq, tool);
    },
    iserror: function (data) {
        if (typeof data == 'object' || data.substring(0, 1) == '{' || data.substring(0, 1) == '[') {
            return false;
        }
        if ($(data).find('#error-message').length > 0) {
            tool.alertError('错误!', $(data).find('#error-message').html());
            return true;
        } else if ($(data).find('#logout-error').length > 0) {
            tool.alertLogin();
            return true;
        } else if ($(data).find('#logout-error-other-login').length > 0) {
            tool.alertLogin('您的账号正在其他设备登录！当前自动退出。');
            return true;
        } else if ($(data).find('#error-info-404').length > 0) {
            tool.alertError('错误!', '网络繁忙，请稍后重试~');
            return true;
        }
        return false;
    },
    getlog: function (el, lcbm, wid) {
        $.post(tool.initParams(tool.procee + 's/biz/ajaxProcess/getLog'), {
            'lcbm': lcbm, 'wid': wid
        }, function (data) {
            if (tool.iserror(data)) {
                return false;
            }
            $('#logmodel').remove();
            $('#log_main_btn').remove();
            var htm = '<div class="modal fade" id="logmodel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="width: 90%;left: 5%;">' +
                '<div class="modal-dialog" role="document">' +
                '<div class="modal-content">' +
                '<div class="modal-header">' +
                '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
                ' <h4 class="modal-title" id="myModalLabel">操作记录</h4>' +
                '</div>' +
                '<div class="modal-body">' +
                data.log +
                '</div>' +
                '<div class="modal-footer">' +
                ' <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>' +
                '</div>' +
                '</div>' +
                ' </div>' +
                '</div><button id="log_main_btn" type="button" class="btn btn-primary" style="display: none;" data-toggle="modal" data-target="#logmodel">' +
                '日志' +
                '</button>';
            $(el).parents('.form-horizontal').append(htm);
            $('#log_main_btn').click();
        });
    },
    getlog_htm: function (lcbm, wid, id) {
        $.post(tool.initParams(tool.procee + 's/biz/ajaxProcess/getLog'), {
            'lcbm': lcbm, 'wid': wid
        }, function (data) {
            if (tool.iserror(data)) {
                return false;
            }
            $('#' + id).html(data.log);
        });
    },
    showlog_all: function (el, wid, lcbm) {
        tool.openview(el, basePath + '/s/biz/process/alllog/' + wid + '/' + lcbm, '查看更多操作记录');
    },
    openimport: function (info) {
        window.parent.tool.openimport(info);
    },
    closeimport: function () {
        window.parent.tool.closeimport();
    },
    initbtnQx: function (form_t, lcbm, nd, xq) {
        $.post(tool.initParams(tool.procee + 's/biz/ajaxProcess/isstart'), {
            'nd': nd,
            'xq': xq,
            'lcbm': lcbm
        }, function (data) {
            if (tool.iserror(data)) {
                return false;
            }
            if (data.count == '0') {//没开启
                form_t.find('button,a').each(function () {
                    if ($(this).attr('ssyhqx') == '2' || $(this).attr('ssyhqx') == '3') {
                        $(this).remove();
                    }
                });
            }
        });
    },
    initbtnQxBack: function (form_t, lcbm, nd, xq, p) {
        $.post(tool.initParams(tool.procee + 's/biz/ajaxProcess/isstart'), {
            'nd': nd,
            'xq': xq,
            'lcbm': lcbm
        }, function (data) {
            if (tool.iserror(data)) {
                return false;
            }
            if (data.count == '0') {//没开启
                p.btnBack();
            }
        });
    },
    /**
     * 关闭当前tab页
     */
    closeCurrentTab: function () {
        var href = window.location.href;
        href = href.substr(href.indexOf('/s/'), href.length);
        $btn = $('[data-id*="' + href + '"].J_menuTab', parent.document).find('i.fa-times-circle');
        if ($btn.length > 0) {
            $btn.click();
        }
    },
    /**
     * 刷新指定tab
     */
    reloadTab: function (url) {
        $('[data-id*="' + url + '"].J_menuTab', parent.document).dblclick();
    },
    /**
     * 刷新当前页面
     */
    reload: function () {
        location.reload();
    },
    /**
     * 禁用可编辑表格编辑功能
     */
    disableEditTable: function () {
        $('.edit-table-body .edit-table-operation').addClass('hide');
    },
    /**
     * 启用可编辑表格编辑功能
     */
    enableEditTable: function () {
        $('.edit-table-body .edit-table-operation').removeClass('hide');
    },
    /**
     * 删除文件
     * @param el this
     * @param path 文件路径
     */
    deleteFileRow: function (el, path) {
//        if (path.indexOf('file_zs') > -1) {
//            $.ajax({
//                url: basePath + '/s/ajax/deleteFile',
//                type: "post",
//                data: {
//                    'path': path
//                },
//                dataType: "json",
//                error: function (XMLHttpRequest, textStatus, errorThrown) {
//                    tool.ajaxError(XMLHttpRequest, textStatus, errorThrown, backdrop);
//                },
//                success: function (data) {
//                    if (data.oper_res) {
//                        var $delTr = $(el).parents('tr');
//                        $delTr.find(".btn").css("border-color", "#fff");
//                        $delTr.addClass("isdelete").find("td").css({"background-color": "#FF3300"}).fadeOut(1000, function () {
//                            $(this).parents('tr').remove();
//                        });
//                    } else {
//                        tool.alertWarning(data.message);
//                    }
//                }
//            });
//        } else {
        var $delTr = $(el).parents('tr');
        $delTr.find(".btn").css("border-color", "#fff");
        $delTr.addClass("isdelete").find("td").css({"background-color": "#FF3300"}).fadeOut(1000, function () {
            $(this).parents('tr').remove();
        });
//        }
    },
    addUploadAttachmentRow: function (data, fileUpload) {
        if (fileUpload == null) {
            fileUpload = tool.fileUpload;
        }
        var index = fileUpload.find('table tbody').find('tr:last').attr('data-index');
        if (index != null && index != '') {
            index = Number(index) + 1;
        } else {
            index = 0;
        }
        var list = fileUpload.find('table').attr('data-list');
        fileUpload.find('table tbody').append('<tr data-index="' + index + '"><td><input name="' + list + '[' + index + '].name" value="' + data.fileold + '" hidden>' +
            '<input name="' + list + '[' + index + '].path" value="' + data.filePath + '" hidden><i class="fa ' + tool.getFileIcon(data.fileold) + '"></i> ' + data.fileold + '</td>' +
            '<td class="tc"><a class="btn btn-xs btn-blue tooltips" data-placement="top" data-original-title="删除" onclick="tool.deleteFileRow(this,\'' + data.filePath + '\')" href="javascript:void(0)"><i class="fa fa-times"></i></a> ' +
            '<a class="btn btn-xs btn-blue tooltips" data-placement="top" data-original-title="下载" onclick="tool.downloadfile(\'' + data.filePath + '\')" href="javascript:void(0)"><i class="fa fa-download"></i></a></td></tr>');
    },
    addUploadImageRow: function (data, fileUpload) {
        if (fileUpload == null) {
            fileUpload = tool.fileUpload;
        }
        var index = fileUpload.find('table tbody').find('tr:last').attr('data-index');
        if (index != null && index != '') {
            index = Number(index) + 1;
        } else {
            index = 0;
        }
        var list = fileUpload.find('table').attr('data-list');
        var url = basePath + '/photoshow.jsp?path=' + data.filePath;
        fileUpload.find('table tbody').append('<tr data-index="' + index + '"><td><input name="' + list + '[' + index + '].name" value="' + data.fileold + '" hidden>' +
            '<input name="' + list + '[' + index + '].path" value="' + data.filePath + '" hidden> <img onclick="tool.previewImage(this)" class="thumbnail" src="' + url + '"></td>' +
            '<td class="tc"><a class="btn btn-xs btn-blue tooltips" data-placement="top" data-original-title="删除" onclick="tool.deleteFileRow(this,\'' + data.filePath + '\')" href="javascript:void(0)"><i class="fa fa-times"></i></a> ' +
            '<a class="btn btn-xs btn-blue tooltips" data-placement="top" data-original-title="下载" onclick="tool.downloadfile(\'' + data.filePath + '\')" href="javascript:void(0)"><i class="fa fa-download"></i></a></td></tr>');
    },
    addUploadVideoRow: function (data, fileUpload) {
        if (fileUpload == null) {
            fileUpload = tool.fileUpload;
        }
        var index = fileUpload.find('table tbody').find('tr:last').attr('data-index');
        if (index != null && index != '') {
            index = Number(index) + 1;
        } else {
            index = 0;
        }
        var list = fileUpload.find('table').attr('data-list');
        var videoPath = data.filePath;
        var url = data.url;
        $.ajax({
            url: basePath + '/s/ajax/getVideoPreview',
            type: "post",
            data: {
                'filePath': videoPath
            },
            dataType: "json",
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                tool.ajaxError(XMLHttpRequest, textStatus, errorThrown);
            },
            success: function (data) {
                if (data.res) {
                    fileUpload.find('table tbody').append('<tr data-index="' + index + '"><td><input name="' + list + '[' + index + '].name" value="' + data.fileold + '" hidden>' +
                        '<input name="' + list + '[' + index + '].path" value="' + videoPath + '" hidden><input name="' + list + '[' + index + '].preview" value="' + data.filePath + '" hidden> <img onclick="tool.previewVideo(\'' + url + '\')" class="thumbnail" src="' + basePath + '/photoshow.jsp?path=' + data.filePath + '"></td>' +
                        '<td class="tc"><a class="btn btn-xs btn-blue tooltips" data-placement="top" data-original-title="删除" onclick="tool.deleteFileRow(this,\'' + videoPath + '\')" href="javascript:void(0)"><i class="fa fa-times"></i></a> ' +
                        '<a class="btn btn-xs btn-blue tooltips" data-placement="top" data-original-title="下载" onclick="tool.downloadfile(\'' + videoPath + '\')" href="javascript:void(0)"><i class="fa fa-download"></i></a></td></tr>');
                } else {
                    tool.alertWarning('操作失败', data.msg);
                }
            }
        });

    },
    previewImage: function (el) {
        $(el).parent().attr('is-see', 'true');
        if (window.top != window.self && window.parent.tool != null) {
            window.parent.tool.previewImageUrl($(el).attr('src'));
        } else {
            $(el).viewer({
                navbar: false
            });
        }
    },
    previewImageByPath: function (path) {
        tool.previewImageByUrl(basePath + '/photoshow.jsp?path=' + path);
    },
    previewImageByUrl: function (url) {
        window.parent.tool.previewImageUrl(url);
    },
    previewVideo: function (url) {
        window.parent.bootbox.dialog({
            title: '视频播放',
            className: 'preview-video',
            message: '<div class="row"><div class="col-xs-12"><video src="' + basePath + url + '" controls preload></video></div></div>',
            buttons: {
                close: {
                    label: "关闭",
                    className: "btn-default btn-sm",
                    callback: function () {

                    }
                }
            }
        });
    },
    initFileIcon: function () {
        $('i[data-file-name]').each(function () {
            $(this).addClass(tool.getFileIcon($(this).attr('data-file-name')))
        });
    },
    /**
     * 根据文件名获取文件字体库图标
     * @param filename
     * @returns {string}
     */
    getFileIcon: function (filename) {
        var temp = filename.substr(filename.indexOf('.') + 1, filename.length);
        temp = temp.toLowerCase();
        if (temp == 'txt') {//文本
            return 'fa-file-text-o';
        } else if (temp == 'zip' || temp == 'rar') {//压缩文件
            return 'fa-file-zip-o';
        } else if (temp == 'mp3' || temp == 'aac' || temp == 'wav' || temp == 'wma' || temp == 'cda' || temp == 'flac' || temp == 'm4a' || temp == 'mid' ||
            temp == 'mka' || temp == 'mp2' || temp == 'mpa' || temp == 'mpc' || temp == 'ape' || temp == 'ofe' || temp == 'ofr' || temp == 'ogg' || temp == 'r4' ||
            temp == 'wv' || temp == 'tta' || temp == 'ac3' || temp == 'dts') {//音频
            return 'fa-file-audio-o';
        } else if (temp == 'avi' || temp == 'asf' || temp == 'wmv' || temp == 'avs' || temp == 'flv' || temp == 'mkv' || temp == 'mov' || temp == '3gp' ||
            temp == 'mp4' || temp == 'mpeg' || temp == 'dat' || temp == 'ogm' || temp == 'vob' || temp == 'rm' || temp == 'rmvb' || temp == 'ts' || temp == 'tp' ||
            temp == 'ifo' || temp == 'nsv') {//视频
            return 'fa-file-movie-o';
            //BMP、JPG、JPEG、PNG、GIF
        } else if (temp == 'bmp' || temp == 'jpg' || temp == 'jpeg' || temp == 'png' || temp == 'gif') {//图片
            return 'fa-file-image-o';
        } else if (temp == 'xml') {
            return 'fa-file-excel-o';
        } else if (temp == 'pdf') {
            return 'fa-file-pdf-o';
        } else if (temp == 'docx' || temp == 'doc' || temp == 'dot' || temp == 'docm') {
            return 'fa-file-word-o';
        } else if (temp == 'xlsx' || temp == 'xls') {
            return 'fa-file-excel-o';
        } else if (temp == 'pptx' || temp == 'ppt' || temp == 'pot') {
            return 'fa-file-powerpoint-o';
        } else if (temp == 'java' || temp == 'css' || temp == 'js' || temp == 'html' || temp == 'php') {
            return 'fa-file-code-o';
        } else {
            return 'fa-file';
        }
    },
    validationElement: function ($elements) {
        var flag = true;
        $elements.each(function () {
            if (!$(this).validationEngine('validate')) {
                flag = false;
                return false;
            }
        });
        return flag;
    },
    /**
     * 初始化图表
     * @param config
     * 示例: http://127.0.0.1:9080/pros/s/components#highcharts
     */
    initchart: function (config) {
        var chart = {};
        var plotOptions = {};
        if (config.type == 'pie') {
            $(config.selector).highcharts({
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false
                },
                title: {
                    text: config.title
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            color: '#000000',
                            connectorColor: '#000000',
                            format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                        }
                    }
                },
                series: [{
                    type: config.type,
                    name: config.yCompany,
                    data: config.data
                }]
            });
        } else {
            chart = {
                type: config.type
            }
            $(config.selector).highcharts({
                chart: chart,
                title: {
                    text: config.title,
                    x: -20 //center
                },
                subtitle: {
                    text: config.subtitle,
                    x: -20
                },
                xAxis: {
                    categories: config.xData
                },
                yAxis: {
                    title: {
                        text: config.yCompany
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                tooltip: {
                    valueSuffix: config.suffix
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle',
                    borderWidth: 0
                },
                series: config.data
            });
        }
    },
    /**
     * 选择字段
     * @param json([[\'id1\',\'字段1\'],[\'id2\',\'字段2\'],[\'id3\',\'字段3\'],[\'id4\',\'字段4\'],[\'id5\',\'字段5\']])
     */
    choseParam: function (json) {
        tool.openModal({'remote': tool.initParams('/pros/s/biz/chose/list'), 'data': 'json=' + json}, '80%', false);
    },
    /**
     * 回调
     * @param param([\'id1\',\'id3\',\'id5\'])
     */
    choseParamBack: function (param) {
        $('div[role="dialog"]').modal('hide');
        //下面的方法请在页面重写
        page.choseParamBack(param);
    },
    /**
     * 验证用户是否有按钮操作权限
     * @param userRights 用户操作权限 sample -- 1,2,3
     * @param btnRights 按钮权限 sample 1,2
     */
    authenticationAuthority: function (userRights, btnRights) {
        if (!isBlank(userRights)) {
            if (isBlank(btnRights) || btnRights == 'null') {
                return true;
            } else {
                userRights = userRights.split(',');
                btnRights = btnRights.split(',');
                for (var i = 0; i < btnRights.length; i++) {
                    for (var j = 0; j < userRights.length; j++) {
                        if (btnRights[i].trim() == userRights[j].trim()) {
                            return true;
                        }
                    }
                }
                return false;
            }
        } else {
            return true;
        }
    },
    /**
     * 根据选择器初始化自动高度textarea
     * @param selector
     */
    initAutosize: function (selector) {
        var $els = $(selector);
        if ($els.length > 0) {
            $els.autosize();
        }
    },
    /**
     * 初始化富文本编辑器
     * @param selector
     */
    initSummerNoteBySelector: function (selector) {
        tool.initSummerNote($(selector));
    },
    /**
     * 初始化富文本编辑器
     * @param $els
     */
    initSummerNote: function ($els) {
        $els.each(function () {
            var _thisNote = $(this);
            _thisNote.summernote({
                height: 300,
                tabsize: 2,
                lang: 'zh-CN',
                oninit: function () {
                    if (_thisNote.code() == "" || _thisNote.code().replace(/(<([^>]+)>)/ig, "") == "") {
                        _thisNote.code(_thisNote.attr("placeholder"));
                    }
                },
                onfocus: function () {
                    if (_thisNote.code() == _thisNote.attr("placeholder")) {
                        _thisNote.code("");
                    }
                },
                onblur: function () {
                    if (_thisNote.code() == "" || _thisNote.code().replace(/(<([^>]+)>)/ig, "") == "") {
                        _thisNote.code(_thisNote.attr("placeholder"));
                    }
                }
            });
        });
    },
    /**
     * data:{"wid":ids,"zcd":"true"}
     * bbname:t_gx_gjjxj_sqb.cpt
     * frpath:'<%=ClientUtil.getString("fr.path") %>'
     */
    print: function (frpath, bbname, data) {
        var url = frpath + "?reportlet=/" + bbname;
        FR.doHyperlinkByPost(url, data, 'REPORT');
    },
    /**
     * 初始化日期插件
     * @param selector
     */
    initDatetimepickerBySelector: function (selector) {
        tool.initDatetimepicker($(selector));
    },
    /**
     * 初始化日期插件
     * @param $els
     */
    initDatetimepicker: function ($els) {
        if ($els.length > 0) {
            $els.each(function () {
                var el = $(this);
                var config = {};
                config.val = el.val();
                config.format = el.attr("data-format");
                config.minDate = el.attr("data-minDate");
                config.maxDate = el.attr("data-maxDate");
                config.viewMode = el.attr("data-viewMode");
                if (isBlank(config.minDate)) {
                    config.minDate = null;
                }
                if (isBlank(config.maxDate)) {
                    config.maxDate = null;
                }
                config.minDateElement = el.attr("data-min-date-element");
                config.maxDateElement = el.attr("data-max-date-element");
                if (isBlank(config.format)) {
                    config.format = "YYYY-MM-DD";
                }
                config.$maxDateElement = $('#' + config.maxDateElement);
                config.$minDateElement = $('#' + config.minDateElement);

                //如果设置了最大时间
                if (config.maxDateElement != null && config.maxDateElement != '' &&
                    config.$maxDateElement.length > 0 && config.$maxDateElement.attr('data-element-type') == 'datetimepicker') {
                    el.datetimepicker({
                        viewMode: config.viewMode,
                        format: config.format
                    });
                    el.on("dp.change", function (e) {
                        config.$maxDateElement.data("DateTimePicker").minDate(e.date);
                    });

                } else {
                    var _config = {format: config.format};
                    _config.viewMode = config.viewMode;
                    if (isNotBlank(config.minDate)) {
                        _config.minDate = config.minDate;
                    }
                    if (isNotBlank(config.maxDate)) {
                        _config.maxDate = config.maxDate;
                    }
                    el.datetimepicker(_config);
                }

                //如果设置了最小时间
                if (config.minDateElement != null && config.minDateElement != '' &&
                    config.$minDateElement.length > 0 && config.$minDateElement.attr('data-element-type') == 'datetimepicker') {
                    el.datetimepicker({
                        viewMode: config.viewMode,
                        format: config.format,
                        useCurrent: false
                    });
                    el.on("dp.change", function (e) {
                        config.$minDateElement.data("DateTimePicker").maxDate(e.date);
                    });
                } else {
                    var _config = {format: config.format};
                    _config.viewMode = config.viewMode;
                    if (isNotBlank(config.minDate)) {
                        _config.minDate = config.minDate;
                    }
                    if (isNotBlank(config.maxDate)) {
                        _config.maxDate = config.maxDate;
                    }
                    el.datetimepicker(_config);
                }
                if (isBlank(config.val)) {
                    el.val('');
                }
            });
        }

    },
    /**
     * 初始化下拉插件
     * @param selector
     */
    initSelectBySelector: function (selector) {
        tool.initSelect($(selector));
    },
    /**
     * 初始化下拉插件
     * @param $els
     */
    initSelect: function ($els) {
        if ($els.length > 0) {
            $els.each(function () {
                var el = $(this);
                if (!isBlank(el.attr("data-table-name"))) {
                    var table_name = el.attr("data-table-name"); //表名
                    var field_id = el.attr("data-field-id"); //select>value
                    var field_text = el.attr("data-field-name");//select>text
                    var up_file_id = el.attr("data-field-up-id"); //上级过滤字段名
                    var up_file_val = el.attr("data-file-up-val"); //上级过滤字段值 仅需填写第一个
                    var data_field_query = el.attr("data-file-query"); //过滤字段名
                    var data_field_val = el.attr("data-query-val"); //过滤字段值
                    if (isBlank(up_file_val)) up_file_val = "";
                    if (isBlank(data_field_val)) data_field_val = "";
                    //如果table_name 为 t_sys_code 字典表 field_id field_text up_file_id up_file_val data_field_query 可为空,将自动设置默认值
                    if (table_name == "t_sys_code" || table_name == "v_sys_code") {
                        if (isBlank(field_id) && isBlank(field_text) && isBlank(up_file_id) && isBlank(up_file_val) && isBlank(data_field_query)) {
                            field_id = "zdbm";
                            field_text = "zdmc";
                            // up_file_id = "";
                            // up_file_val = "";
                            // data_field_query = "zdlb";
                        }
                    }
                    if (table_name == "t_sys_depart") {
                        if (isBlank(field_id) && isBlank(field_text) && isBlank(up_file_id)) {
                            field_id = "departid";
                            field_text = "departname";
                            // up_file_id = "updepartid";
                        }
                    }
                    var data = {
                        "table_name": table_name,
                        "field_id": field_id,
                        "field_text": field_text,
                        "up_file_id": up_file_id,
                        "up_file_val": encodeURI(up_file_val),
                        "data_field_query": data_field_query,
                        "data_field_val": encodeURI(data_field_val),
                        "cur_val": el.attr('data-cur-val'),
                        "order_field": el.attr('data-order-field'),
                        "order_type": el.attr('data-order-type'),
                        "otherQuery": el.attr('data-other-query')
                    };
                    if (isBlank(el.attr("data-childselect"))) {//不是级联
                        loadSelectOption(basePath + "/s/ajax/getDataForSelect", data, el);
                    } else {
                        el.attr('dont-init', 'true');
                        el.on("change", function () {//当级联下拉 改变时,重新加载子下拉框
                            var chlid_select = $(el.attr("data-childselect"));
                            while (chlid_select.length != 0) {//重置所有子下拉
                                chlid_select.html("<option value=''>&nbsp;</option>");
                                initSelect(chlid_select);
                                chlid_select = $(chlid_select.attr("data-childselect"));
                            }
                            var child_object = $(el.attr("data-childselect"));
                            var up_val = child_object.attr('data-cur-val');
                            if (isBlank(up_val)) {
                                up_val = el.val();
                            } else {
                                up_val = el.find("option:selected").attr('data-val');
                            }
                            loadSelectOption(basePath + "/s/ajax/getDataForSelect", {
                                "table_name": child_object.attr("data-table-name"),
                                "field_id": child_object.attr("data-field-id"),
                                "field_text": child_object.attr("data-field-name"),
                                "up_file_id": child_object.attr("data-field-up-id"),
                                "data_field_query": child_object.attr("data-file-query"),
                                "data_field_val": child_object.attr("data-query-val"),
                                "order_field": child_object.attr('data-order-field'),
                                "order_type": child_object.attr('data-order-type'),
                                "cur_val": child_object.attr('data-cur-val'),
                                "up_file_val": up_val,
                                "otherQuery": el.attr('data-other-query')
                            }, child_object);
                        });
                        if (!el.attr("data-noauto-init")) {
                            loadSelectOption(basePath + "/s/ajax/getDataForSelect", data, el);
                        } else {
                            initSelect(el);
                        }
                    }
                } else if (!isBlank(el.attr("data-select-url"))) {
                    loadSelectOption(el.attr("data-select-url"), null, el);
                } else {
                    initSelect(el);
                }
            });
        }
    },
    /**
     * 初始化下拉插件(搜索)
     * @param selector
     */
    initSearchSelectBySelector: function (selector) {
        tool.initSearchSelect($(selector));
    },
    /**
     * 初始化下拉插件(搜索)
     * @param $els
     */
    initSearchSelect: function ($els) {
        if ($els.length > 0) {
            $els.each(function () {
                var url = $(this).attr("data-select-url");
                url = tool.initParams(url);
                $(this).select2({
                    language: "zh-CN",
                    theme: "bootstrap",
                    width: '100%',
                    ajax: {
                        url: url,
                        dataType: 'json',
                        delay: 250,
                        type: 'post',
                        data: function (params) {
                            return {
                                q: encodeURI(params.term)
                            };
                        },
                        processResults: function (data) {
                            return {
                                results: eval(data)
                            };
                        },
                        transport: function (params, success, failure) {
                            var $request = $.ajax(params);

                            $request.then(success);
                            $request.fail(failure);

                            return $request;
                        },
                        cache: true
                    },
                    escapeMarkup: function (markup) {
                        return markup;
                    }, // let our custom formatter work
                    minimumInputLength: 1
                });
            });
        }
    },
    /**
     * 初始化bootstrap-select
     * @param selector
     */
    initBootstrapSelectBySelector: function (selector) {
        tool.initBootstrapSelect($(selector));
    },
    /**
     * 初始化bootstrap-select
     * @param $els
     */
    initBootstrapSelect: function ($els) {
        if ($els.length > 0) {
            $els.each(function () {
                var el = $(this);
                if (!isBlank(el.attr("data-table-name"))) {
                    var table_name = el.attr("data-table-name"); //表名
                    var field_id = el.attr("data-field-id"); //select>value
                    var field_text = el.attr("data-field-name");//select>text
                    var up_file_id = el.attr("data-field-up-id"); //上级过滤字段名
                    var up_file_val = el.attr("data-file-up-val"); //上级过滤字段值 仅需填写第一个
                    var data_field_query = el.attr("data-file-query"); //过滤字段名
                    var data_field_val = el.attr("data-query-val"); //过滤字段值
                    if (isBlank(up_file_val)) up_file_val = "";
                    if (isBlank(data_field_val)) data_field_val = "";
                    //如果table_name 为 t_sys_code 字典表 field_id field_text up_file_id up_file_val data_field_query 可为空,将自动设置默认值
                    if (table_name == "t_sys_code" || table_name == "v_sys_code") {
                        if (isBlank(field_id) && isBlank(field_text) && isBlank(up_file_id) && isBlank(up_file_val) && isBlank(data_field_query)) {
                            field_id = "zdbm";
                            field_text = "zdmc";
                        }
                    }
                    if (table_name == "t_sys_depart") {
                        if (isBlank(field_id) && isBlank(field_text) && isBlank(up_file_id)) {
                            field_id = "departid";
                            field_text = "departname";
                        }
                    }
                    var data = {
                        "table_name": table_name,
                        "field_id": field_id,
                        "field_text": field_text,
                        "up_file_id": up_file_id,
                        "up_file_val": encodeURI(up_file_val),
                        "data_field_query": data_field_query,
                        "data_field_val": encodeURI(data_field_val),
                        "cur_val": el.attr('data-cur-val'),
                        "order_field": el.attr('data-order-field'),
                        "order_type": el.attr('data-order-type'),
                        "otherQuery": el.attr('data-other-query')
                    };
                    if (isBlank(el.attr("data-childselect"))) {//不是级联
                        loadSelectOption(basePath + "/s/ajax/getDataForSelect", data, el, false);
                        el.selectpicker();
                    }
                } else if (!isBlank(el.attr("data-select-url"))) {
                    loadSelectOption(el.attr("data-select-url"), null, el, false);
                    el.selectpicker();
                } else {
                    el.selectpicker();
                }
            });
        }
    },
    /**
     * 根据选择器初始化iCheck
     * @param selector 选择器
     */
    initiCheckBySelector: function (selector) {
        tool.initiCheck($(selector));
    },
    /**
     * 初始化iCheck
     * @param $els jquery对象
     */
    initiCheck: function ($els) {
        $els.each(function () {
            var $el = $(this);
            if ($.fn.iCheck) {
                if ($el.hasClass('grey')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_minimal-grey',
                        radioClass: 'iradio_minimal-grey',
                        increaseArea: '10%'
                    });
                }
                if ($el.hasClass('green')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_minimal-green',
                        radioClass: 'iradio_minimal-green',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('teal')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_minimal-aero',
                        radioClass: 'iradio_minimal-aero',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('orange')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_minimal-orange',
                        radioClass: 'iradio_minimal-orange',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('purple')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_minimal-purple',
                        radioClass: 'iradio_minimal-purple',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('yellow')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_minimal-yellow',
                        radioClass: 'iradio_minimal-yellow',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('square-black')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_square',
                        radioClass: 'iradio_square',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('square-grey')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_square-grey',
                        radioClass: 'iradio_square-grey',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('square-red')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_square-red',
                        radioClass: 'iradio_square-red',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('square-green')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_square-green',
                        radioClass: 'iradio_square-green',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('square-teal')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_square-aero',
                        radioClass: 'iradio_square-aero',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('square-orange')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_square-orange',
                        radioClass: 'iradio_square-orange',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('square-purple')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_square-purple',
                        radioClass: 'iradio_square-purple',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('square-yellow')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_square-yellow',
                        radioClass: 'iradio_square-yellow',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('flat-black')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_flat',
                        radioClass: 'iradio_flat',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('flat-grey')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_flat-grey',
                        radioClass: 'iradio_flat-grey',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('flat-red')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_flat-red',
                        radioClass: 'iradio_flat-red',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('flat-green')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_flat-green',
                        radioClass: 'iradio_flat-green',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('flat-teal')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_flat-aero',
                        radioClass: 'iradio_flat-aero',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('flat-orange')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_flat-orange',
                        radioClass: 'iradio_flat-orange',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('flat-purple')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_flat-purple',
                        radioClass: 'iradio_flat-purple',
                        increaseArea: '10%' // optional
                    });
                }
                if ($el.hasClass('flat-yellow')) {
                    $el.iCheck({
                        checkboxClass: 'icheckbox_flat-yellow',
                        radioClass: 'iradio_flat-yellow',
                        increaseArea: '10%' // optional
                    });
                }
                $el.on('ifToggled', function (event) {
                    $el.blur();
                });
            }
        });
    },
    /**
     * 固定表头/列
     * @param selector 选择器
     * @param config 配置
     */
    fixerTableBySelector: function (selector, config) {
        tool.fixerTable($(selector), config);
    },
    /**
     * 固定表头/列
     * @param $el jquery对象
     * @param config 配置
     */
    fixerTable: function ($el, config) {
        var $parent = $el.parent();
        if ($parent.hasClass('fixer')) {
            // //获取表格高度,更改容器高度
            // $parent.css({
            //     height: $el.height() + 10
            // });
            try {
                //如果配置为空,则取table[data-col]
                if (config == null) {
                    if ($el.attr('data-left') != null && $el.attr('data-left') != '') {
                        config = {
                            left: $el.attr('data-left')
                        }
                    }
                }
                $el.tableHeadFixer(config);
            } catch (e) {
                console.warn('固定表头 > 方法tableHeadFixer不存在,请检查是否引入tableHeadFixer.js');
            }
        } else {
            console.warn('固定表头 > 未找到父元素.fixer');
        }
    },
    initvalidationEngine: function (selector) {
        try {
            $(selector).validationEngine({
                showOneMessage: true
            });
        } catch (e) {
            console.warn('初始化表单验证 ' + selector + ' 失败,如无需表单验证,忽略此警告');
        }

    },
    initAlertHis: function () {
        $('.alert.alert-his').each(function () {
            if ($(this).attr('data-his') == 'true') {
                $(this).append('<i data-state="hide" class="fa fa-chevron-down his-btn"></i>');

                $(this).find('.his-btn').click(function () {
                    var $el = $(this);
                    var state = $el.attr('data-state');
                    if (state == 'hide') {
                        $el.attr('data-state', 'show');
                        $el.removeClass('fa-chevron-down').addClass('fa-chevron-up');
                        $el.parents('.alert').removeClass('alert-his');
                    } else {
                        $el.attr('data-state', 'hide');
                        $el.removeClass('fa-chevron-up').addClass('fa-chevron-down');
                        $el.parents('.alert').addClass('alert-his');
                    }
                });
            } else {
                $(this).removeClass('alert-his');
            }
        });
    },
    initBtnShow: function () {
        $('body').find('button.btn,a.btn').each(function () {
            var $el = $(this);
            var userJurisdiction = $el.attr('ssyhqx');
            var groupJurisdiction = $el.attr('data-group-jurisdiction');
            var userJuris = tool.authenticationAuthority(tool.usertype, userJurisdiction);
            var groupJuris = tool.authenticationAuthority(tool.group, groupJurisdiction);
            /**
             * 以下情况会将按钮删除
             * 1.用户验证未通过/用户组未设置
             * 2.用户未设置/用户组验证未通过
             * 3.用户验证未通过/用户组验证未通过
             */
            if ((!userJuris && (isBlank(groupJurisdiction) || groupJurisdiction == 'null' )) ||
                (!groupJuris && (isBlank(userJurisdiction) || userJurisdiction == 'null')) ||
                !groupJuris && !userJuris) {
                $(this).remove();
            }
        });
    },
    /**
     * 检查浏览器是否支持html5上传
     * @returns {boolean}
     */
    supportHtml5: function () {
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
            var ieversion = new Number(RegExp.$1);
            if (ieversion == 8 || ieversion == 9) {
                isIE8 = true;
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    },
    /**
     * 设置页面只读
     * 1.隐藏所有按钮
     * @param $el 只读区域
     */
    setReadonly: function ($el) {
        $el.find('.btn').addClass('hide');
    },
    /**
     * 显示提示窗口
     * @param title 标题
     * @param content 内容
     * @param animate 动画效果
     */
    openTipWindow: function (icon, title, content, animate) {
        var config = {};
        if (isBlank(animate)) {
            animate = 'fadeInDown'
        }
        if (isBlank(icon)) {//默认为提示图标
            config.icon = 'fa-lightbulb-o';
        } else {
            config.icon = icon;
        }
        config.title = title;
        config.content = content;
        config.animateIn = animate;
        config.animateOut = animate.replace('In', 'Out');
        tool.openTipWindowByConfig(config);
    },
    openTipWindowByConfig: function (config) {
        var id = getNewElementId();
        var _html = '<div id="' + id + '" class="panel panel-white pt10 notifications hide"><div class="panel-body"><div class="row"><div class="col-xs-12">' +
            '<i class="fa fa-times close"></i><i class="icon fa ' + config.icon + '"></i>' +
            '<h2 class="title">' + config.title + '</h2><p class="content">' + config.content + '</p>' +
            '</div></div></div></div>';
        var $panel = $('body').append(_html).find('#' + id);
        $panel.removeClass('hide').removeClass(config.animateIn + ' animated').addClass(config.animateIn + ' animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
            $(this).removeClass(config.animateIn + ' animated');
        });
        $panel.find('i.close').click(function () {
            $panel.removeClass(config.animateOut + ' animated').addClass(config.animateOut + ' animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
                $(this).removeClass(config.animateOut + ' animated').addClass('hide');
                $panel.remove();
            });
            ;
        });
    },
    runInit: function () {
        var $body = $('body');
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
            var ieversion = new Number(RegExp.$1);
            if (ieversion <= 8) {
                isIE8 = true;
                $body.addClass('isIE8');
            } else if (ieversion == 9) {
                isIE9 = true;
                $body.addClass('isIE9');
            }
        }
        // Detection for Mobile Device
        if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
            isMobile = true;
            $body.addClass('isMobile');
        }
    },
    /**
     * 初始化表格最大显示字符长度
     */
    initTableEllipsis: function () {
        $('[data-ell-length]').each(function () {
            var $el = $(this);
            var width = $el.attr('data-ell-length');
            if ($el.find('a').length > 0) {//a链接
                $el.find('a').addClass('db ell auto').css('width', width);
            } else {
                $el.html('<span class="db ell auto">' + $el.html() + '</span>').find('span').css('width', width);
            }
        });
    }
}
subPage = {
    /**
     * 子页面关闭回调函数
     * 如需要,请在页面重写,每次子页面关闭将重置
     */
    closeCallback: function () {
    },
    /**
     * 保存之后的回调函数
     * @param data 保存结果
     * @param $form_element 表单对象
     */
    save_callback: function (data, $form_element) {
    },
    lc_callback: function (el, data) {

    }
}
/********************** String工具类***************/
//trim去掉字符串两边的指定字符,默去空格
String.prototype.trim = function (tag) {
    if (!tag) {
        tag = '\\s';
    } else {
        if (tag == '\\') {
            tag = '\\\\';
        } else if (tag == ',' || tag == '|' || tag == ';') {
            tag = '\\' + tag;
        } else {
            tag = '\\s';
        }
    }
    eval('var reg=/(^' + tag + '+)|(' + tag + '+$)/g;');
    return this.replace(reg, '');
};
//字符串截取后面加入...
String.prototype.interceptString = function (len) {
    if (this.length > len) {
        return this.substring(0, len) + "...";
    } else {
        return this;
    }
}
//将一个字符串用给定的字符变成数组
String.prototype.toArray = function (tag) {
    if (this.indexOf(tag) != -1) {
        return this.split(tag);
    } else {
        if (this != '') {
            return [this.toString()];
        } else {
            return [];
        }
    }
}
//只留下数字(0123456789)
String.prototype.toNumber = function () {
    return this.replace(/\D/g, "");
}
//保留中文
String.prototype.toCN = function () {
    var regEx = /[^\u4e00-\u9fa5\uf900-\ufa2d]/g;
    return this.replace(regEx, '');
}
//转成int
String.prototype.toInt = function () {
    var temp = this.replace(/\D/g, "");
    return isNaN(parseInt(temp)) ? this.toString() : parseInt(temp);
}
//是否是以XX开头
String.prototype.startsWith = function (tag) {
    return this.substring(0, tag.length) == tag;
}
//是否已XX结尾
String.prototype.endWith = function (tag) {
    return this.substring(this.length - tag.length) == tag;
}
//StringBuffer
var StringBuffer = function () {
    this._strs = new Array;
};
StringBuffer.prototype.append = function (str) {
    this._strs.push(str);
};
StringBuffer.prototype.toString = function () {
    return this._strs.join("");
};
String.prototype.replaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
}
function isRefresh() {
    return false;
}
function isSubmitForm() {
    return false;
}
function isFunction(fn) {
    return Object.prototype.toString.call(fn) === '[object Function]';
}
/**
 * 获取随机数
 * @returns {*}
 */
function getNewElementId() {
    var temp = tool.randomString(3);
    return temp + (Math.floor(Math.random() * 10000));
}
/**
 * 初始化select2插件
 * @param el
 */
function initSelect(el) {
    var minimumResultsForSearch = Infinity;
    if (el.attr("data-show-searchbox")) {
        minimumResultsForSearch = 0;
    }
    var val = el.attr("data-val");
    if (isBlank(val)) {
        val = el.attr("data-value");
    }
    var defaultvalue = el.attr('defaultvalue');
    if (defaultvalue != undefined && defaultvalue != 'undefined' && defaultvalue != null && defaultvalue != ''
        && ($('#wid').val() == null || $('#wid').val() == '')) {
        val = defaultvalue;
    }
    if (!isBlank(val)) {
        el.val(val.split(","));
    }
    var childselect = el.attr("data-childselect");
    if (!isBlank(childselect)) {
        el.change();
    }
    var formatState = el.attr("data-format");
    if (!isBlank(formatState)) {
        formatState = new Function('data', formatState);
        el.select2({
            minimumResultsForSearch: minimumResultsForSearch,
            templateResult: formatState,
            templateSelection: formatState,
            theme: "bootstrap",
            width: '100%'
        });
    } else {
        el.select2({
            minimumResultsForSearch: minimumResultsForSearch,
            theme: "bootstrap",
            width: '100%'
        });
        // el.trigger("change");
    }
}
/**
 * 初始化语言
 */
function init_lanagure() {
    //var uulanguage = (navigator.language || navigator.browserLanguage).toLowerCase();
    try {
        if (parent.cookielang != "" && parent.cookielang != null) {
            if (parent.cookielang == "en") {
                $("[data-localize]").each(function () {
                    var attr = $.trim($(this).html());
                    $(this).attr("data-localize", attr);
                    $(this).html(valueforkey(attr, parent.jsonlanguage));
                })
                $('[placeholder]').each(function () {
                    var txt = valueforkey($(this).attr("placeholder"), parent.jsonlanguage);
                    $(this).attr("placeholder", txt);
                })
            }
        }
    } catch (e) {
        // TODO: handle exception
    }

}
function youdao(txt) {
    try {
        if (parent.cookielang == "en") {
            $.ajax(
                {
                    type: 'post',
                    url: '/pros/s/ajax/getyoudaovalue?txt=' + encodeURI(encodeURI(txt)),
                    dataType: 'text',
                    async: false,
                    success: function (data) {
                        txt = data;
                    },
                    error: function () {
                        console.log('fail');
                    }
                }
            );
        }
    } catch (e) {
        // TODO: handle exception
    }

    return txt;
}

function loadSelectOption(url, data, el, init) {
    if (el != null && el.length > 0) {
        if (init == null) {
            init = true;
        }
        var data_show_id = el.attr("data-show-id"); //是否显示编码
        $.ajax({
            url: tool.initParams(url),
            type: "post",
            data: data,
            dataType: "json",
            timeout: 1000 * 20,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus == "timeout") {
                    el.html('').append("<option value=''>请求超时</option>");
                    console.error('加载id:' + el.context.id + ' > option超时.');
                } else {
                    console.error(el.context.id + '数据加载失败,请查看Network请求中返回信息.');
                }
                if (init) {
                    initSelect(el);
                }
                //如果加载失败,重新加载一次,如第二次还失败,则不再重新加载
                var retryCount = el.attr('data-retry-count');
                if ('1' != retryCount) {//加载次数不为1
                    el.attr('data-retry-count', '1');
                    setTimeout(loadSelectOption(url, data, el, init), 1000);
                }
            },
            success: function (data) {
                el.html('').append("<option value=''>&nbsp;</option>");
                if (data != null && data.res) {
                    data = data.data;
                    for (var i = 0; i < data.length; i++) {
                        if (data_show_id == '1')
                            el.append('<option data-val="' + data[i].curVal + '" value="' + data[i].id + '">' + data[i].text + '(' + data[i].id + ')</option>');
                        else
                            el.append('<option data-val="' + data[i].curVal + '" value="' + data[i].id + '">' + data[i].text + '</option>');
                    }
                } else {
                    console.error('加载id:' + el.context.id + ' > option时,发生' + data.msg + '异常.');
                }
                if (init) {
                    initSelect(el);
                }
            }
        });
    }
}